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>
using namespace std;
#define int long long
vector<int> chef;
vector<int> s;
vector<vector<int> > con;
int n;
int find(int a){
if(chef[a]==a) return a;
return chef[a]=find(chef[a]);
}
void unite(int a, int b){
assert(find(a)!=find(b));
s[find(a)]+=s[find(b)];
for(int i=0; i<n; i++){
if(find(i)!=i) continue;
con[find(i)][find(a)]+=con[find(i)][find(b)];
}
for(int i=0; i<n; i++){
if(find(i)!=i) continue;
con[find(a)][find(i)]+=con[find(b)][find(i)];
}
chef[find(b)]=find(a);
}
void initialize(int32_t a){
n=a;
chef.assign(n, 0);
iota(chef.begin(), chef.end(), 0);
s.assign(n, 1);
con.assign(n, vector<int> (n, 0));
}
int32_t hasEdge(int32_t u, int32_t v){
assert(find(u)!=find(v));
con[find(u)][find(v)]++;
con[find(v)][find(u)]++;
//cout << con[find(u)][find(v)] << " " << s[find(u)] << " " << s[find(v)] << "\n";
if(con[find(u)][find(v)]==s[find(u)]*s[find(v)]){
unite(u, v);
return 1;
}
return 0;
}
/*signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
initialize(n);
for(int i=0; i<(n*(n-1))/2; i++){
int a, b;
cin >> a >> b;
cout << hasEdge(a, b) << "\n" << flush;
for(int i=0; i<n; i++){
cout << i << " " << find(i) << "\n";
for(int j=0; j<n; j++){
cout << j << " " << find(j) << " " << con[find(i)][find(j)] << "\n";
}
}
cout << "hallo\n" << flush;
}
}*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |