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>
#define endl '\n'
#define mod 1000000007
using namespace std;
vector<int>adj[2000001];
int dsu[2000001],rnk[2000001];
set<pair<int,int>>d;
int N;
int Find(int x){
if(dsu[x] == x) return x;
return dsu[x] = Find(dsu[x]);
}
void Unite(int a, int b){
a = Find(a); b = Find(b);
if(rnk[a] < rnk[b]) swap(a,b);
if(rnk[a] == rnk[b]) rnk[a]++;
dsu[b] = a;
}
void initialize(int n) {
N = n;
for(int i = 1; i <= n; i++) dsu[i] = i;
}
int hasEdge(int u, int v) {
u++; v++;
int set_a = Find(u), set_b = Find(v);
if(set_a == set_b) return 0;
vector<int>x,y;
for(int i = 1; i <= N; i++){
if(Find(i) == set_a) x.push_back(i);
if(Find(i) == set_b) y.push_back(i);
}
for(int i = 0; i < x.size(); i++){
for(int j = 0; j < y.size(); j++){
if(x[i] == u && y[j] == v) continue;
if(x[i] == v && y[j] == u) continue;
if(!d.count({x[i],y[j]})) return 0;
}
}
Unite(u,v);
d.insert({u,v});
d.insert({v,u});
return 1;
}
Compilation message (stderr)
game.cpp: In function 'int hasEdge(int, int)':
game.cpp:38:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i = 0; i < x.size(); i++){
| ~~^~~~~~~~~~
game.cpp:39:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int j = 0; j < y.size(); j++){
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |