#ifndef SUPERTREES_H_INCLUDED
#define SUPERTREES_H_INCLUDED
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
struct DSU{
vector<int>par;
DSU(int n){
par.assign(n, -1);
}
int FindRep(int u){
if(par[u] < 0)return u;
return par[u] = FindRep(par[u]);
}
void Union(int u, int v){
u = FindRep(u);
v = FindRep(v);
if(u == v)return;
if(par[u] > par[v])swap(u, v);
par[u] += par[v];
par[v] = u;
}
bool IsConnected(int u, int v){
u = FindRep(u);
v = FindRep(v);
return (u == v);
}
};
void build(vector<vector<int>>b);
int construct(vector<vector<int>>p){
int n = p.size();
DSU dsu1(n);
vector<vector<int>>b(n, vector<int>(n));
for(int i = 0;i < n;++i){
for(int j = 0;j < n;++j){
if(p[i][j] && i != j){
dsu1.Union(i, j);
b[i][j] = b[j][i] = 1;
}
}
}
for(int i = 0;i < n;++i){
for(int j = 0;j < n;++j){
if(i != j && !p[i][j] && dsu1.IsConnected(i, j))return 0;
}
}
for(int i = 0;i < n;++i){
int p = dsu1.FindRep(i);
if(dsu1.par[p] == -2)return 0;
}
build(b);
return 1;
}
#endif // SUPERTREES_H_INCLUDED
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
9 ms |
1108 KB |
Output is correct |
9 |
Correct |
166 ms |
22016 KB |
Output is correct |
10 |
Incorrect |
0 ms |
212 KB |
Too many ways to get from 0 to 3, should be 2 found no less than 3 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Too many ways to get from 1 to 4, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |