Submission #895404

#TimeUsernameProblemLanguageResultExecution timeMemory
895404SalihSahinGame (IOI14_game)C++14
100 / 100
374 ms27468 KiB
#include<bits/stdc++.h> #define pb push_back #define mp make_pair using namespace std; #include "game.h" int N; vector<vector<int> > sz; vector<vector<int> > edge; vector<int> par; int find(int a){ if(a == par[a]) return a; return par[a] = find(par[a]); } void merge(int a, int b){ a = find(a), b = find(b); if(a == b) return; if(sz[a].size() < sz[b].size()){ par[a] = b; for(auto itr: sz[a]){ sz[b].pb(itr); } } else{ par[b] = a; for(auto itr: sz[b]){ sz[a].pb(itr); } } } void initialize(int n){ N = n; vector<int> v; v.assign(n, 1); par.resize(n); sz.resize(n); for(int i = 0; i < n; i++){ par[i] = i; sz[i].pb(i); edge.pb(v); } } int hasEdge(int u, int v) { int choice = 0; int ou = u, ov = v; u = find(u), v = find(v); if(u == v){ edge[ou][ov] = edge[ov][ou] = 0; return 0; } for(auto i: sz[u]){ for(auto j: sz[v]){ if(edge[i][j]){ choice++; if(choice > 1) break; } } if(choice > 1) break; } if(choice == 1){ merge(u, v); return 1; } else{ edge[ou][ov] = edge[ov][ou] = 0; return 0; } } /* int read_int() { int x; assert(scanf("%d", &x) == 1); 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; } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...