#include "supertrees.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
struct DSU{
vi parent, size;
vector<bool> kec, dvojka;
void init(int n){
kec.resize(n, false);
dvojka.resize(n, false);
for(int i = 0; i < n; i++){
parent.pb(i);
size.pb(1);
}
}
bool is_dva(int v){
return dvojka[v];
}
int get_size(int v){
return size[v];
}
int find_parent(int v){
if(parent[v] == v) return v;
return parent[v] = find_parent(parent[v]);
}
void merge(int a, int b, int tip){
a = find_parent(a);
b = find_parent(b);
bool done = false;
if(a != b){
if(size[b] > size[a])
swap(a, b);
done = true;
if(tip == 1) kec[a] = true;
if(tip == 2) dvojka[a] = true;
parent[b] = a;
size[a] += size[b];
}
if(!done){
if(tip == 1) kec[a] = true;
if(tip == 2) dvojka[a] = true;
}
}
};
int construct(vector<vi> p) {
int n = p.size();
vector<vi> answer;
bool possible = true;
for(int i = 0; i < n; i++){
for(auto t : p[i]){
if(t == 3) possible = false;
}
}
for(int i = 0; i < n; i++){
vi pom(n,0);
answer.pb(pom);
}
DSU dsu1, dsu2;
dsu1.init(n);
dsu2.init(n);
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
if(p[i][j] == 1)
dsu1.merge(i, j, 1);
else if(p[i][j] == 2)
dsu2.merge(i, j, 2);
}
}
//assert(false);
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
if(dsu1.find_parent(i) == dsu1.find_parent(j) && p[i][j] == 0)
possible = false;
if(dsu2.find_parent(i) == dsu2.find_parent(j) && p[i][j] == 0)
possible = false;
if(p[i][j] == 2 && dsu1.find_parent(i) == dsu1.find_parent(j))
possible = false;
}
}
//assert(false);
int first[n], last[n];
memset(first, -1, sizeof first);
memset(last, -1, sizeof last);
for(int i = 0; i < n; i++){
int a = dsu2.find_parent(i);
//cout<<i<<" "<<a<<endl;
if(last[a] == -1){
last[a] = i;
first[a] = i;
}
else{
//cout<<"HERE"<<endl;
answer[i][last[a]] = 1;
answer[last[a]][i] = 1;
last[a] = i;
}
}
//assert(false);
for(int i = 0; i < n; i++){
int a = dsu2.find_parent(i);
if(dsu2.get_size(a) < 3 && dsu2.get_size(a) > 1) possible = false;
else if(dsu2.get_size(a) >= 3){
answer[last[a]][first[a]] = 1;
answer[first[a]][last[a]] = 1;
}
}
memset(last, -1, sizeof last);
for(int i = 0; i < n; i++){
int a = dsu1.find_parent(i);
if(last[a] == -1) last[a] = i;
else{
//cout<<i<<" "<<last[a]<<" "<<endl;
answer[i][last[a]] = 1;
answer[last[a]][i] = 1;
}
}
if(!possible) return 0;
build(answer);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
179 ms |
22004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
179 ms |
22004 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1104 KB |
Output is correct |
13 |
Correct |
153 ms |
22060 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
74 ms |
12048 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
39 ms |
5700 KB |
Output is correct |
21 |
Correct |
155 ms |
22052 KB |
Output is correct |
22 |
Correct |
151 ms |
21968 KB |
Output is correct |
23 |
Correct |
183 ms |
21964 KB |
Output is correct |
24 |
Correct |
154 ms |
21992 KB |
Output is correct |
25 |
Correct |
63 ms |
12048 KB |
Output is correct |
26 |
Correct |
63 ms |
12164 KB |
Output is correct |
27 |
Correct |
155 ms |
21968 KB |
Output is correct |
28 |
Correct |
156 ms |
22164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
7 ms |
1160 KB |
Output is correct |
9 |
Correct |
154 ms |
22028 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
154 ms |
22056 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
712 KB |
Output is correct |
17 |
Correct |
85 ms |
12044 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
38 ms |
5692 KB |
Output is correct |
22 |
Correct |
153 ms |
22020 KB |
Output is correct |
23 |
Correct |
151 ms |
22020 KB |
Output is correct |
24 |
Correct |
168 ms |
22004 KB |
Output is correct |
25 |
Correct |
66 ms |
12164 KB |
Output is correct |
26 |
Correct |
63 ms |
12160 KB |
Output is correct |
27 |
Correct |
157 ms |
21968 KB |
Output is correct |
28 |
Correct |
157 ms |
21964 KB |
Output is correct |
29 |
Correct |
62 ms |
12044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
39 ms |
5740 KB |
Output is correct |
5 |
Correct |
169 ms |
21996 KB |
Output is correct |
6 |
Correct |
151 ms |
22068 KB |
Output is correct |
7 |
Correct |
162 ms |
22008 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
38 ms |
5768 KB |
Output is correct |
10 |
Correct |
152 ms |
22016 KB |
Output is correct |
11 |
Correct |
165 ms |
22056 KB |
Output is correct |
12 |
Correct |
158 ms |
22028 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Incorrect |
0 ms |
212 KB |
Too many ways to get from 0 to 4, should be 1 found no less than 2 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
179 ms |
22004 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1104 KB |
Output is correct |
13 |
Correct |
153 ms |
22060 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
74 ms |
12048 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
39 ms |
5700 KB |
Output is correct |
21 |
Correct |
155 ms |
22052 KB |
Output is correct |
22 |
Correct |
151 ms |
21968 KB |
Output is correct |
23 |
Correct |
183 ms |
21964 KB |
Output is correct |
24 |
Correct |
154 ms |
21992 KB |
Output is correct |
25 |
Correct |
63 ms |
12048 KB |
Output is correct |
26 |
Correct |
63 ms |
12164 KB |
Output is correct |
27 |
Correct |
155 ms |
21968 KB |
Output is correct |
28 |
Correct |
156 ms |
22164 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1160 KB |
Output is correct |
37 |
Correct |
154 ms |
22028 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1108 KB |
Output is correct |
41 |
Correct |
154 ms |
22056 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
3 ms |
712 KB |
Output is correct |
45 |
Correct |
85 ms |
12044 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
38 ms |
5692 KB |
Output is correct |
50 |
Correct |
153 ms |
22020 KB |
Output is correct |
51 |
Correct |
151 ms |
22020 KB |
Output is correct |
52 |
Correct |
168 ms |
22004 KB |
Output is correct |
53 |
Correct |
66 ms |
12164 KB |
Output is correct |
54 |
Correct |
63 ms |
12160 KB |
Output is correct |
55 |
Correct |
157 ms |
21968 KB |
Output is correct |
56 |
Correct |
157 ms |
21964 KB |
Output is correct |
57 |
Correct |
62 ms |
12044 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
5 ms |
724 KB |
Output is correct |
61 |
Correct |
74 ms |
12048 KB |
Output is correct |
62 |
Correct |
0 ms |
212 KB |
Output is correct |
63 |
Correct |
0 ms |
212 KB |
Output is correct |
64 |
Correct |
0 ms |
212 KB |
Output is correct |
65 |
Incorrect |
38 ms |
5732 KB |
Too many ways to get from 1 to 183, should be 1 found no less than 2 |
66 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
179 ms |
22004 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1104 KB |
Output is correct |
13 |
Correct |
153 ms |
22060 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
74 ms |
12048 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
39 ms |
5700 KB |
Output is correct |
21 |
Correct |
155 ms |
22052 KB |
Output is correct |
22 |
Correct |
151 ms |
21968 KB |
Output is correct |
23 |
Correct |
183 ms |
21964 KB |
Output is correct |
24 |
Correct |
154 ms |
21992 KB |
Output is correct |
25 |
Correct |
63 ms |
12048 KB |
Output is correct |
26 |
Correct |
63 ms |
12164 KB |
Output is correct |
27 |
Correct |
155 ms |
21968 KB |
Output is correct |
28 |
Correct |
156 ms |
22164 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1160 KB |
Output is correct |
37 |
Correct |
154 ms |
22028 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1108 KB |
Output is correct |
41 |
Correct |
154 ms |
22056 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
3 ms |
712 KB |
Output is correct |
45 |
Correct |
85 ms |
12044 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
38 ms |
5692 KB |
Output is correct |
50 |
Correct |
153 ms |
22020 KB |
Output is correct |
51 |
Correct |
151 ms |
22020 KB |
Output is correct |
52 |
Correct |
168 ms |
22004 KB |
Output is correct |
53 |
Correct |
66 ms |
12164 KB |
Output is correct |
54 |
Correct |
63 ms |
12160 KB |
Output is correct |
55 |
Correct |
157 ms |
21968 KB |
Output is correct |
56 |
Correct |
157 ms |
21964 KB |
Output is correct |
57 |
Correct |
62 ms |
12044 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
39 ms |
5740 KB |
Output is correct |
62 |
Correct |
169 ms |
21996 KB |
Output is correct |
63 |
Correct |
151 ms |
22068 KB |
Output is correct |
64 |
Correct |
162 ms |
22008 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
38 ms |
5768 KB |
Output is correct |
67 |
Correct |
152 ms |
22016 KB |
Output is correct |
68 |
Correct |
165 ms |
22056 KB |
Output is correct |
69 |
Correct |
158 ms |
22028 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Incorrect |
0 ms |
212 KB |
Too many ways to get from 0 to 4, should be 1 found no less than 2 |
73 |
Halted |
0 ms |
0 KB |
- |