Codeforces 466E Information Graph
Information Graph
把询问离线之后就能随便搞了, 去check一下是不是祖先, 可以用倍增也能用dfs序。
#include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, int> #define SZ(x) ((int)x.size()) #define ull unsigned long long using namespace std;const int N = 1e5 + 7; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-8;int n, m, cnt, deg[N], fa[N], op[N], x[N], y[N], depth[N], f[N][20]; bool vis[N]; bool ans[N]; vector<int> G[N]; vector<int> qus[N];int getRoot(int x) {return x == fa[x] ? x : fa[x] = getRoot(fa[x]); }void Merge(int x, int y) {fa[getRoot(x)] = getRoot(y); }void dfs(int u, int fa, int idx) {vis[u] = idx;depth[u] = depth[fa] + 1;f[u][0] = fa;for(int i = 1; i < 20; i++)f[u][i] = f[f[u][i - 1]][i - 1];for(int& v : G[u]) if(!vis[v]) dfs(v, u, idx); }bool check(int u, int v) {if(depth[u] < depth[v]) return false;if(vis[u] != vis[v]) return false;if(getRoot(u) != getRoot(v)) return false;for(int i = 19; i >= 0; i--)if(depth[f[u][i]] >= depth[v])u = f[u][i];return u == v; }int main() {scanf("%d%d", &n, &m);for(int i = 1; i <= n; i++) fa[i] = i;for(int i = 1; i <= m; i++) {scanf("%d%d", &op[i], &x[i]);if(op[i] != 2) scanf("%d", &y[i]);if(op[i] == 3) qus[y[i]].push_back(i);if(op[i] == 1) G[y[i]].push_back(x[i]), deg[x[i]]++;}for(int i = 1; i <= n; i++)if(!deg[i]) dfs(i, 0, ++cnt);cnt = 0;for(int i = 1; i <= m; i++) {if(op[i] == 1) {Merge(x[i], y[i]);} else if(op[i] == 2) {cnt++;for(auto& p : qus[cnt])if(check(x[i], x[p]))ans[p] = true;}}for(int i = 1; i <= m; i++)if(op[i] == 3) printf("%s\n", ans[i] ? "YES" : "NO");return 0; }/**/
转载于:https://www.cnblogs.com/CJLHY/p/10391176.html
Codeforces 466E Information Graph相关推荐
- CodeForces - 1494E A-Z Graph(构造+思维)
题目链接:https://vjudge.net/problem/CodeForces-1494E 题目大意:给出一个初始时只有 nnn 个点的有向带权图,需要执行 mmm 次操作,每次操作分为下列三种 ...
- Codeforces 1093D Beautiful Graph
题目链接:http://codeforces.com/contest/1093/problem/D 第一次做这种题目,染色+组合数学.. 假设这个图里有奇数环,那么肯定是不行的,因为无论怎么样都是偶数 ...
- codeforces CF986C AND Graph 建圖 dfs
$ \rightarrow $ 戳我進CF原題 C. AND Graph time limit per test: 4 seconds memory limit per test: 256 megab ...
- codeforces gym-101745 C-Infinite Graph Game 分块
题意 题目链接 给出一个顶点带权无向图. 定义访问操作:访问一个点,就要把与这个点相邻的点的权值全部都加到答案里去,然后给这个顶点的权值/2.现在给出一个无穷的访问序列中的一个循环节,求最终答案的极限 ...
- Codeforces 题目合集+分类+代码 【Updating...】【361 in total】
961A - Tetris 模拟 ...
- paper reading:[renormalization]Semi-supervised Classification with Graph Convolutional Networks
paper reading:[Renormalization Trick] Semi-supervised classification with graph convolutional networ ...
- A Comprehensive Survey on Graph Neural Networks(图神经网络综合研究)
A Comprehensive Survey on Graph Neural Networks 图神经网络综合研究 Zonghan Wu, Shirui Pan, Member, IEEE, Feng ...
- 阅读Skeleton-Based Action Recognition with Directed Graph Neural Networks(CVPR2019)
Skeleton-Based Action Recognition with Directed Graph Neural Networks是Lei Shi等人的另一篇文章,和之前的2s-AGCN以 ...
- Knowledge Graph Embedding: A Survey of Approaches and Applications 摘要
想看原文戳这里 1. introduction (1) the definition of KG A KG is a multi-relational graph composed of entiti ...
最新文章
- caffe 下一些参数的设置
- html动态加载js方法,如何通过JavaScript动态加载js
- 【经典课程】李宏毅机器学习2020版正式上线!!!
- 第10章 指针(五) 使用地址-------指针的引用
- ECSHOP 助手使用
- TensorFlow中设置学习率的方式
- Oracle 12c In-Memory Option应用解析
- 你应该知道的Excel 2007小技巧
- Java 线程的生命周期
- 数据库-事务并发操作问题及并发的控制
- IdentityServer4 4.x版本 配置Scope的正确姿势
- WordPress /wp-admin/includes/post.php user_ID 参数操作权限提升漏洞
- python 写入文件编码_使用Python写入文本文件时的编码问题
- Unix安装BerkeleyDB
- 计算机顶会论文写作科研利器
- anaconda pycharm_搭建 Python 高效开发环境: Pycharm + Anaconda
- 解决PCoIP连接View 5.0虚拟桌面超时断开导致无法再次登录的问题
- C++ std::move/std::forward/完美转发
- 树莓派学习2-连接蓝牙音箱进行语音播放
- 程序员福音,关于如何使用Markdown写出一份漂亮的简历 —— 程序员简历 | md文档简历制作教程
热门文章
- uml边界类例子_面向对象UML笔记
- js的tree数组对象扁平化思否_js 中的tree型数组如何去重与合并?
- html实现横向轮播,js实现横向轮播效果
- 样条线怎么挤出平面_最速降线的故事
- Another Distinct Values
- java url压缩_URL短地址压缩算法 微博短地址原理解析 (Java实现)
- Go语言基础进阶—程序结构—命名
- 安装PaddleOCR遇到ERROR: Command errored out with exit status 1:command: ‘f:\python3.7\python.exe‘ -u -c
- 牛客网暑期ACM多校训练营(第五场): A. gpa(01分数规划)
- qscoj:默契值(状压DP)