Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Oct 11th, 2018 62 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #include <cstdio>
  2. char line[100];
  3. int un[100001];
  4. int t, n;
  5. int find(int a) {
  6.    if (a == un[a]) return a;
  7.    return (un[a] = find(un[a]));
  8. }
  9. char c;
  10. int u, v, pu, pv;
  11. int fail,suc;
  12.  
  13. int main()
  14. {
  15.     scanf("%d", &t);
  16.     while(t--) {
  17.         fail = suc = 0;
  18.         scanf("%d ", &n);
  19.         for (int i = 0; i <= n; ++i) un[i] = i;
  20.         while (gets(line)) {
  21.             if (line[0] == '\0') break;
  22.             sscanf(line, "%c %d %d", &c, &u, &v);
  23.             //printf("%c %d %d \n", c,u,v);
  24.             pu = find(u);
  25.             pv = find(v);
  26.            
  27.             if (c == 'c') un[pv] = pu;
  28.             else if (pu == pv) ++suc;
  29.             else ++fail;
  30.         }
  31.         printf("%d,%d\n", suc, fail);
  32.         if (t) putchar('\n');
  33.     }
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top