#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] != 1) 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(i == j) continue;
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;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1180 KB |
Output is correct |
7 |
Correct |
171 ms |
22048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1180 KB |
Output is correct |
7 |
Correct |
171 ms |
22048 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1128 KB |
Output is correct |
13 |
Correct |
171 ms |
21944 KB |
Output is correct |
14 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1180 KB |
Output is correct |
7 |
Correct |
171 ms |
22048 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1128 KB |
Output is correct |
13 |
Correct |
171 ms |
21944 KB |
Output is correct |
14 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1180 KB |
Output is correct |
7 |
Correct |
171 ms |
22048 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1128 KB |
Output is correct |
13 |
Correct |
171 ms |
21944 KB |
Output is correct |
14 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |