标签:font with round bec where 思路 col mos NPU
Input
Output
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <queue> 5 #include <vector> 6 #include <cmath> 7 8 using namespace std; 9 10 #define ll long long 11 #define pb push_back 12 #define fi first 13 #define se second 14 15 const int N = 2000 << 1; 16 struct node 17 { 18 int rt, v; 19 }fa[N]; 20 21 int Find(int x) 22 { 23 if(fa[x].rt == x) return x; 24 else{ 25 int tmp = fa[x].rt; 26 fa[x].rt = Find(tmp); 27 fa[x].v = (fa[x].v + fa[tmp].v) % 2; 28 return fa[x].rt; 29 } 30 } 31 32 bool Union(int x, int y) 33 { 34 int fax = Find(x); 35 int fay = Find(y); 36 if(fax != fay){ 37 fa[fay].rt = fax; 38 fa[fay].v = (fa[x].v + 1 - fa[y].v) % 2; 39 return true; 40 }else{ 41 if(0 == (fa[x].v + 1 - fa[y].v) % 2) return true; 42 else return false; 43 } 44 } 45 46 void solve() 47 { 48 int T; 49 scanf("%d", &T); 50 for(int _case = 1; _case <= T; ++_case){ 51 int n, m; 52 scanf("%d%d", &n, &m); 53 for(int i = 0; i <= n; ++i){ 54 fa[i].rt = i; 55 fa[i].v = 0; 56 } 57 vector<pair<int ,int > > info; 58 int x, y; 59 for(int i = 1; i <= m; ++i){ 60 scanf("%d%d", &x, &y); 61 info.pb({x, y}); 62 } 63 64 int error = 0; 65 for(int i = 0; i < m; ++i){ 66 x = info[i].fi; 67 y = info[i].se; 68 if(!Union(x, y)){ 69 error = 1; 70 break; 71 } 72 } 73 74 printf("Scenario #%d:\n", _case); 75 printf("%s\n\n", error == 1 ? "Suspicious bugs found!" : "No suspicious bugs found!"); 76 } 77 } 78 79 int main() 80 { 81 82 solve(); 83 84 return 0; 85 }
标签:font with round bec where 思路 col mos NPU
原文地址:https://www.cnblogs.com/SSummerZzz/p/13284000.html