This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
int n;
set<pair<int,int>> ed;
int up[1505];
int Up(int x)
{
if (up[x]==x) return x;
return up[x]=Up(up[x]);
}
void dsu(int a, int b)
{
a=Up(a),b=Up(b);
up[a]=b;
}
bool connected()
{
for (int i=0;i<n;i++) up[i]=i;
for (auto it : ed) dsu(it.first,it.second);
int komp=0;
for (int i=0;i<n;i++) if (up[i]==i) komp++;
return komp==1;
}
void initialize(int N) {
n=N;
for (int i=0;i<n;i++)
for (int j=i+1;j<n;j++) ed.insert({i,j});
}
int hasEdge(int u, int v) {
if (u>v) swap(u,v);
ed.erase({u,v});
if (connected()) return 0;
return ed.insert({u,v}),1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |