Submission #649419

#TimeUsernameProblemLanguageResultExecution timeMemory
649419quocnguyen1012Game (IOI14_game)C++14
100 / 100
409 ms25180 KiB
#ifndef LOCAL #include "game.h" #endif #include "bits/stdc++.h" using namespace std; const int maxn = 1505; int avail[maxn][maxn]; int par[maxn]; int N; int find(int u) { return (par[u] < 0 ? u : par[u] = find(par[u])); } void initialize(int n) { N=n; for (int i=0; i<n; ++i) par[i] = -1; for (int i=0;i<n;++i) { for(int j=0;j<n;++j) avail[i][j]=1; } } int hasEdge(int u, int v) { u = find(u); v = find(v); assert(find(u) != find(v)); if (avail[u][v] == 1) { par[v]=u; for(int i=0;i<N;++i){ if(par[i]<0 and u != i) { avail[u][i]=avail[i][u]=avail[u][i]+avail[v][i]; } } return 1; } else { avail[u][v]--; avail[v][u]--; return 0; } } #ifdef LOCAL int read_int() { int x; cin >> x; return x; } int main() { int n, u, v; n = read_int(); initialize(n); for (int i = 0; i < n * (n - 1) / 2; i++) { u = read_int(); v = read_int(); printf("%d\n", hasEdge(u, v)); } return 0; } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...