LibreOJ #109. 并查集
二次联通门 : LibreOJ #109. 并查集
/* LibreOJ #109. 并查集 并查集 */ #include <cstdio> #define Max 4000090 #define Mod 998244353 void read (int &now) { now = 0; register char word = getchar (); while (word < '0' || word > '9') word = getchar (); while (word >= '0' && word <= '9') { now = now * 10 + word - '0'; word = getchar (); } } int N, M; int father[Max]; int Find (int x) { return father[x] == x ? x : father[x] = Find (father[x]); } inline void Merge (int x, int y) { int now_1 = Find (x); int now_2 = Find (y); if (x != y) father[x] = y; return ; } inline int Query (int x, int y) { return Find (x) == Find (y); } int number[Max]; int main (int argc, char *argv[]) { read (N); read (M); int x, y, type; register int cur = 0; for (register int i = 1; i <= N; i ++) father[i] = i; long long Answer = 0; for (; M --; ) { read (type); read (x); read (y); x ++; y ++; if (type == 0) Merge (x, y); else Answer = ((Answer << 1) + Query (x, y)) % Mod; } printf ("%lld", Answer); return 0; }
myj 吊打我Orz,xxy 捆起来打我Orz,myl 文化课上天Orz, lrh 姿势水平敲高Orz, hkd 特别胖Orz%%%,cys 智商感人Orz,syl zz专业Orz,我没有学上, 我们未来一片光明