Submission #237960

#TimeUsernameProblemLanguageResultExecution timeMemory
237960nicolaalexandraGame (IOI14_game)C++14
100 / 100
495 ms25464 KiB
#include <bits/stdc++.h> #include "game.h" #define DIM 1510 using namespace std; int n,i,t[DIM],a[DIM][DIM]; int get_rad (int x){ while (t[x] > 0) x = t[x]; return x; } int hasEdge(int x, int y){ x++, y++; int radx = get_rad(x), rady = get_rad(y); if (radx == rady) return 1; a[radx][rady]++, a[rady][radx]++; if (a[radx][rady] == (-t[radx]) * (-t[rady])){ /// acum ar trebui sa unesc padurile astea if (t[radx] > t[rady]) swap (radx,rady); t[radx] += t[rady]; t[rady] = radx; /// trb sa actualizez matricea a for (int i=1;i<=n;i++){ if (radx == i) continue; a[radx][i] += a[rady][i]; a[i][radx] += a[rady][i]; } return 1; } return 0; } void initialize (int N){ n = N; for (i=1;i<=n;i++) t[i] = -1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...