#include "supertrees.h"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define vi vector<int>
using namespace std;
int parent[1001], sz[1001];
void init(){
for(int i = 0; i < 1000; i++){
parent[i] = i;
sz[i] = 1;
}
}
int find(int v){
if(parent[v] == v) return v;
return parent[v] = find(parent[v]);
}
void combine(int i, int j){
i = find(i);
j = find(j);
if(i == j) return;
if(sz[i] < sz[j]) swap(i, j);
parent[j] = i;
sz[i] += sz[j];
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
bool one = true, two = true, lessTwo = true;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(p[i][j] == 3) return 0;
if(p[i][j] != one) one = false;
if(p[i][j] == 2) lessTwo = false;
}
}
if(one){
vector<vector<int>> b;
for(int i = 0; i < n; i++){
vi arr(n, 0);
if(i >0) arr[i-1]=1;
if(i+1<n) arr[i+1]=1;
b.pb(arr);
}
build(b);
return 1;
}
else if(lessTwo){
init();
for(int i = 0; i < n; i++){
for(int j = i+1; j < n; j++){
if(p[i][j] == 1){
combine(i, j);
}
}
}
int last[n]; // for every branch;
memset(last, -1, sizeof last);
vector<vector<int> > b(n, vector<int>(n));
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(find(i) == find(j)){
b[i][j]=1;
}
}
}
build(b);
return 1;
}
return 0;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:31:19: warning: unused variable 'two' [-Wunused-variable]
31 | bool one = true, two = true, lessTwo = true;
| ^~~
# |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
172 ms |
22056 KB |
Output is correct |
# |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
172 ms |
22056 KB |
Output is correct |
8 |
Incorrect |
0 ms |
212 KB |
b[0][0] is not 0 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
b[0][0] is not 0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
b[0][0] is not 0 |
2 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
172 ms |
22056 KB |
Output is correct |
8 |
Incorrect |
0 ms |
212 KB |
b[0][0] is not 0 |
9 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
172 ms |
22056 KB |
Output is correct |
8 |
Incorrect |
0 ms |
212 KB |
b[0][0] is not 0 |
9 |
Halted |
0 ms |
0 KB |
- |