Submission #983749

#TimeUsernameProblemLanguageResultExecution timeMemory
983749sleepntsheepGame (IOI14_game)C11
100 / 100
287 ms25564 KiB
#include "game.h" #define NN 1500 int n, ds[NN], cross[NN][NN]; int find(int i) { if (ds[i] < 0) return i; return ds[i] = find(ds[i]); } int unite(int i, int j) { i = find(i), j = find(j); if (i == j) return 0; ds[i] += ds[j]; for (int k = 0; k < n; ++k) if (find(k) != j && find(k) != i) cross[i][k] = cross[k][i] = cross[i][k] + cross[j][k]; ds[j] = i; return 1; } void initialize(int n0) { n = n0; for (int i = 0; i < n; ++i) ds[i] = -1; for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) cross[i][j] = cross[j][i] = 1; } int hasEdge(int u, int v) { if (find(u) == find(v)) return 1; u = find(u), v = find(v); --cross[u][v]; --cross[v][u]; if (0 == cross[u][v]) { unite(u, v); return 1; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...