#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3+1;
int comp[N], siz[N];
int getComp(int node){
if (comp[node] != node) comp[node] = getComp(comp[node]);
return comp[node];
}
bool merge(int a, int b, bool y){
a = getComp(a);
b = getComp(b);
if (a != b){
if (!y) return 1;
if (siz[a] > siz[b]) swap(a,b);
siz[b] += siz[a];
comp[a] = b;
return 1;
}
return 0;
}
int construct(vector<vector<int>> p) {
int n = p.size();
for (int i=0; i<n; ++i){
comp[i] = i;
siz[i] = 1;
}
vector<vector<int>> ans(n,vector<int>(n));
for (int i=0; i<n; ++i){
for (int j=i+1; j<n; ++j){
if (p[i][j] == 1){
merge(i,j,1);
ans[i][j] = 1;
ans[j][i] = 1;
}
}
}
for (int i=0; i<n; ++i){
for (int j=i+1; j<n; ++j){
if (p[i][j] == 0 and !merge(i,j,0)) return 0;
}
}
build(ans);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
436 KB |
Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
436 KB |
Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Too few ways to get from 0 to 1, should be 2 found 0 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
436 KB |
Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
436 KB |
Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |