标签:onclick bsp ons 一句话 div body cstring microsoft reg
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 77428 | Accepted: 23067 |
Description
Input
Output
Sample Input
100 7 1 101 1 2 1 2 2 2 3 2 3 3 1 1 3 2 3 1 1 5 5
Sample Output
3
Source
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 6 inline void read(int &x) 7 { 8 x = 0;char ch = getchar(),c = ch; 9 while(ch < ‘0‘ || ch > ‘9‘)c = ch, ch = getchar(); 10 while(ch <= ‘9‘ && ch >= ‘0‘)x = x * 10 + ch - ‘0‘, ch = getchar(); 11 if(c == ‘-‘)x = -x; 12 } 13 14 const int MAXN = 50000 + 10; 15 16 int n,k,fa[MAXN << 2],ans; 17 18 int find(int x) 19 { 20 return x == fa[x] ? x : fa[x] = find(fa[x]); 21 } 22 23 int main() 24 { 25 register int tmp1, tmp2, tmp3, fa1, fb2, fb1, fc2, fc1, fa2; 26 read(n), read(k); 27 for(register int i = n * 3;i >= 1;-- i)fa[i] = i; 28 for(register int i = 1;i <= k;++ i) 29 { 30 read(tmp1), read(tmp2), read(tmp3); 31 if(tmp2 > n || tmp3 > n || tmp2 < 1 || tmp3 < 1) 32 { 33 ++ ans; 34 continue; 35 } 36 if(tmp2 == tmp3 && tmp1 == 2) 37 { 38 ++ ans; 39 continue; 40 } 41 fa1 = find(tmp2), fb1 = find(tmp2 + n), fc1 = find(tmp2 + n + n); 42 fa2 = find(tmp3), fb2 = find(tmp3 + n), fc2 = find(tmp3 + n + n); 43 if(tmp1 == 1) 44 { 45 if(fa1 == fb2 || fa1 == fc2) 46 { 47 ++ ans; 48 continue; 49 } 50 fa[fa1] = fa2; 51 fa[fb1] = fb2; 52 fa[fc1] = fc2; 53 } 54 else 55 { 56 if(fa1 == fa2 || fa1 == fc2) 57 { 58 ++ ans; 59 continue; 60 } 61 fa[fa1] = fb2; 62 fa[fb1] = fc2; 63 fa[fc1] = fa2; 64 } 65 } 66 printf("%d", ans); 67 return 0; 68 }
标签:onclick bsp ons 一句话 div body cstring microsoft reg
原文地址:http://www.cnblogs.com/huibixiaoxing/p/7476722.html