摘要:
给定一棵包含 nn 个节点的有根无向树,节点编号互不相同,但不一定是 1∼n。 有 m 个询问,每个询问给出了一对节点的编号 x 和 y,询问 x 与 y 的祖孙关系。 输入格式 输入第一行包括一个整数 表示节点个数; 接下来 n 行每行一对整数 a 和 b,表示 a 和 b 之间有一条无向边。如果 阅读全文
摘要:
#include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 210; int n, k, m; int a[N], w[N][N]; int f[N][N]; int m 阅读全文
摘要:
#include <bits/stdc++.h> using namespace std; int f[50005],dis[50005]; const int mod=4; int find(int x){ if(x!=f[x]){ int root = find(f[x]); dis[x] = 阅读全文
摘要:
#include <bits/stdc++.h> using namespace std; const int maxn=1e5+5; struct node{ int next,to; }edge[maxn<<1]; int head[maxn<<1],cnt,st[maxn]; void add 阅读全文
摘要:
给定一张 n 个点 m 条边的有向无环图,分别统计从每个点出发能够到达的点的数量。 输入格式 第一行两个整数 N,MN,M,接下来 MM 行每行两个整数 x,yx,y,表示从 xx 到 yy 的一条有向边。 输出格式 输出共 NN 行,表示每个点能够到达的点的数量。 数据范围 1≤N,M≤30000 阅读全文