# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1090025 | onlk97 | Connecting Supertrees (IOI20_supertrees) | C++14 | 1 ms | 348 KiB |
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 "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
struct DSU{
vector <int> dsu;
void init(int n){
dsu.clear();
for (int i=0; i<=n; i++) dsu.push_back(i);
}
int prt(int n){
if (dsu[n]==n) return n;
return dsu[n]=prt(dsu[n]);
}
void unn(int u,int v){
dsu[prt(u)]=dsu[prt(v)];
}
};
int construct(vector <vector <int> > p){
int n=p.size();
DSU d;
d.init(n);
vector <vector <int> > op(n,vector <int>(n,0));
for (int i=0; i<n; i++){
for (int j=i+1; j<n; j++){
if (p[i][j]==1){
d.unn(i,j);
op[i][j]=1; op[j][i]=1;
}
if (p[i][j]==3) return 0;
}
}
for (int i=0; i<n; i++){
for (int j=i+1; j<n; j++){
if ((p[i][j]==1)!=(d.prt(i)==d.prt(j))) return 0;
}
}
for (int i=0; i<n; i++){
if (p[i]!=p[d.prt(i)]) return 0;
}
bool done[n];
for (int i=0; i<n; i++) done[i]=0;
for (int i=0; i<n; i++){
if (d.prt(i)!=i||done[i]) continue;
set <int> s;
s.insert(d.prt(i));
for (int j=i+1; j<n; j++){
if (p[i][j]==2) s.insert(d.prt(j));
}
if (s.size()<3) return 0;
vector <int> vec;
for (int j:s) vec.push_back(j);
for (int j=0; j<s.size(); j++){
op[vec[j]][vec[(j+1)%s.size()]]=1; op[vec[(j+1)%s.size()]][vec[j]]=1;
}
for (int j:vec){
done[j]=1;
for (int k=0; k<n; k++){
if (p[j][k]==2&&s.find(d.prt(k))==s.end()) return 0;
}
}
}
build(op);
return 1;
}
Compilation message (stderr)
# | 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... |