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 <bits/stdc++.h>
#include "game.h"
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1000005
using namespace std;
typedef long long ll;
int n, ata[N], sz[N], deg[N];
int atabul(int x){return ata[x] = (ata[x] == x)?x:atabul(ata[x]);}
void merge(int x, int y){
int xx = atabul(x);
int yy = atabul(y);
if(xx != yy){
ata[xx] = yy;
sz[yy] += sz[xx];
}
}
void initialize(int nn){
n = nn;
for(int i = 1; i <= n; i++){
ata[i] = i;
sz[i] = 1;
}
}
int hasEdge(int u, int v){u++;v++;
int xx = atabul(u);
int yy = atabul(v);
if(sz[xx] + sz[yy] == n){
deg[u]++;deg[v]++;
return 0;
}
if(deg[u] + deg[v] >= n - 2){
merge(xx, yy);
return 1;
}
deg[u]++;deg[v]++;
return 0;
}
// int read_int() {
// int x;
// assert(scanf("%d", &x) == 1);
// return x;
// }
// int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |