UOJ Logo saruka的博客

博客

NOI 2015 程序自动分析

2016-10-03 18:37:45 By saruka

/ Problem: 1059 User: saruka Memory: 256K Time: 5MS Language: G++ Result: Accepted /

include

int getint() { int r = 0, k = 1; char c = getchar(); for(; c < '0' || c > '9'; c = getchar()) if(c == '-') k = -1; for(; c >= '0' && c <= '9'; c = getchar()) r = r 10 + c - '0'; return r k; } const int maxn = 1000100; const int mod = 1000000; int n, T, x, y, e, cnt; int ueq[maxn][2], fa[2 maxn]; inline int hash(int x) { return x > mod ? (mod + x / mod + x % mod): x; } int getfather(int x) { return fa[x] = (fa[x] == x) ? x : getfather(fa[x]); } int main() { T = getint(); while(T--) { cnt = 0; n = getint(); for(int i = 1; i < 2 maxn; i++) fa[i] = i; for(int i = 1; i <= n; i++) { x = getint(); y = getint(); e = getint(); x = hash(x); y = hash(y); if(e == 1) { fa[getfather(x)] = getfather(y); } else { ++cnt; ueq[cnt][0] = x; ueq[cnt][1] = y;
} }
bool flag = 1; for(int i = 1; i <= cnt; i++) { if(getfather(ueq[i][0]) == getfather(ueq[i][1])) { flag = 0; break; } } printf(flag ? ("YES\n") : ("NO\n"));
} return 0; }

评论

WrongAnswer
为什么代码不用```包起来呢? ```c++ #include <cstdio> int main(){ // Todo } ```

发表评论

可以用@mike来提到mike这个用户,mike会被高亮显示。如果你真的想打“@”这个字符,请用“@@”。