Submission #419008

#TimeUsernameProblemLanguageResultExecution timeMemory
419008MasterTasterGame (IOI14_game)C++14
42 / 100
1090 ms6532 KiB
#include <bits/stdc++.h> #include "game.h" #define pb push_back #define ll long long #define pii pair<int, int> #define xx first #define yy second using namespace std; int dsu[1510], rnk[1510]; set<pii> svi; int root(int u) { while (u!=dsu[u]) { dsu[u]=dsu[dsu[u]]; u=dsu[u]; } return u; } void connect(int u, int v) { //if (root(u)==root(v)) return; if (rnk[root(u)]<=rnk[root(v)]) { if (rnk[root(u)]==rnk[root(v)]) rnk[root(v)]++; dsu[root(u)]=root(v); } else dsu[root(v)]=root(u); } void initialize(int n) { for (int i=0; i<n; i++) for (int j=0; j<n; j++) if (i<j) svi.insert({i, j}); for (int i=0; i<n; i++) { dsu[i]=i; rnk[i]=1; } } int hasEdge(int u, int v) { if (u>v) swap(u, v); int ru, rv; ru=root(u); rv=root(v); svi.erase({u, v}); bool moze=true; for (auto par:svi) { int a, b; a=par.xx; b=par.yy; //cout<<a<<" "<<b<<" "<<root(a)<<" "<<root(b)<<" "<<ru<<" "<<rv<<endl; if ((root(a)==ru && root(b)==rv) || (root(a)==rv && root(b)==ru)) { moze=false; break; } } if (!moze) return 0; connect(u, v); return 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...