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>
using namespace std;
const int N = 1507;
int n;
int par[N];
vector<int> el[N];
bool e[N][N];
int con[N][N];
bool unite(int u, int v){
if(el[par[u]].size() < el[par[v]].size()){
swap(u, v);
}
int pr = par[v];
for(int x: el[pr]){
par[x] = par[u];
}
for(int x: el[pr]){
el[par[u]].push_back(x);
for(int i = 0; i < x; i++){
if(!e[i][x]){
con[par[x]][par[i]]++;
con[par[i]][par[x]]++;
}
}
for(int i = x + 1; i < n; i++){
if(!e[x][i]){
con[par[x]][par[i]]++;
con[par[i]][par[x]]++;
}
}
}
return true;
}
void initialize(int _n){
n = _n;
for(int i = 0; i < n; i++){
par[i] = i;
el[i].push_back(i);
}
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
e[i][j] = false;
con[i][j] = 1;
con[j][i] = 1;
}
}
}
int hasEdge(int u, int v){
e[min(u, v)][max(u, v)] = 1;
if(con[par[u]][par[v]] == 1){
unite(u, v);
return 1;
}
con[par[u]][par[v]]--;
con[par[v]][par[u]]--;
return 0;
}
/*int main(){
int _n;
cin >> _n;
initialize(_n);
while(true){
int u, v;
cin >> u >> v;
cout << hasEdge(u, v) << endl;
}
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... |