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 "supertrees.h"
#include <vector>
using namespace std;
typedef vector<int> vi;
#define FORi(i,a,b) for(int i=((int)a);i<((int)b);i++)
#define FOR(i,n) FORi(i,0,n)
int par[10000];
int lef[10000];
int fnd(int a){
if(par[a]==a) return a;
par[a] = fnd(par[a]);
return par[a];
}
void onion(int a, int b){
par[fnd(a)] = fnd(b);
}
int construct(vector<vector<int>> p) {
int n = p.size();
FOR(i,n) par[i] = i;
vector<std::vector<int>> adj(n, vi(n, 0));
int deg[n] = {};
FOR(i,n){
bool none = true;
FOR(j,n){
if(i==j) continue;
if(p[i][j]==2 && fnd(i)!=fnd(j) && none){
onion(i, j);
adj[i][j] = 1;
adj[j][i] = 1;
deg[i]++;
deg[j]++;
none = false;
}
else if(p[i][j]==0 && fnd(i)==fnd(j)){
return 0;
}
}
}
FOR(i,n){
if(deg[i]==1){
FOR(j,n) if(fnd(i)==fnd(j) && deg[j]==1 && i!=j){
deg[i]++;
deg[j]++;
adj[i][j] = 1;
adj[j][i] = 1;
}
}
}
build(adj);
return 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |