#include "supertrees.h"
#include <vector>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define ln "\n"
#define pll pair<ll, ll>
struct DSU{
vector<ll> p;
ll n;
DSU(ll N){
n=N;
p.resize(n, -1);
}
ll get(ll x){
return p[x]==-1?x:p[x]=get(p[x]);
}
bool unite(ll a, ll b){
a=get(a);
b=get(b);
if (a==b) return 0;
p[a]=b;
return 1;
}
};
int construct(std::vector<std::vector<int>> p) {
ll n = (ll)p.size();
bool pos=1;
DSU tr(n);
vector<vector<int>> ans(n, vector<int>(n, 0));
for (ll i=0; i<n; i++){
for (ll j=0; j<n; j++){
if (i==j) continue;
if (p[i][j]){
if (tr.unite(i, j)) ans[i][j]=1;
}
}
}
for (ll i=0; i<n; i++){
for (ll j=0; j<n; j++){
if (tr.get(i)==tr.get(j) and i!=j and p[i][j]==0){
pos=0;
}
}
}
if (!pos) return 0;
build(ans);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
b is not symmetric: b[0][1] (1) != b[1][0] (0) |
3 |
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 |
b is not symmetric: b[0][1] (1) != b[1][0] (0) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
b is not symmetric: b[0][1] (1) != b[1][0] (0) |
3 |
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 |
b is not symmetric: b[0][1] (1) != b[1][0] (0) |
3 |
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 |
b is not symmetric: b[0][1] (1) != b[1][0] (0) |
3 |
Halted |
0 ms |
0 KB |
- |