#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
/*void build(vector<vector<int> > adi){
int n=adi.size();
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
cout << adi[i][j] << " ";
}
cout << "\n";
}
}*/
vector<vector<int> > components(vector<vector<int> >& p, int n, bool& pos){
vector<vector<int> > comp;
vector<bool> vis(n);
vector<int> comp_num(n, -1); int mom=0;
for(int v=0; v<n; v++){
if(vis[v]) continue;
vis[v]=true;
comp.push_back({});
comp.back().push_back(v);
comp_num[v]=mom;
for(int u=0; u<n; u++){
if(u!=v && p[v][u]!=0){
comp.back().push_back(u);
comp_num[u]=mom;
vis[u]=true;
}
}
mom++;
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(comp_num[i]==comp_num[j]){
pos = pos && (p[i][j]!=0 && p[j][i]!=0);
}
else{
pos = pos && (p[i][j]==0 && p[j][i]==0);
}
}
}
return comp;
}
void solve_component(vector<int>& c, int n, vector<vector<int> >& p, vector<vector<int> >& adi, bool& pos){
vector<int> cycle;
vector<bool> vis(n);
for(auto v: c){
if(vis[v]) continue;
cycle.push_back(v);
for(auto u: c){
if(u!=v && p[v][u]==1){
adi[v][u]=1;
adi[u][v]=1;
vis[u]=true;
for(int i=0; i<n; i++){
pos = pos && (p[v][i] == p[u][i]);
}
}
}
}
for(int i=0; i+1<(int)cycle.size(); i++){
adi[cycle[i]][cycle[i+1]]=1;
adi[cycle[i+1]][cycle[i]]=1;
}
if(cycle.size()>1){
adi[cycle[0]][cycle.back()]=1;
adi[cycle.back()][cycle[0]]=1;
}
if(cycle.size()==2){
pos=false;
}
}
int construct(vector<vector<int> > p) {
int n = p.size();
bool pos=true;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(p[i][j]==3){
pos=false;
}
}
}
vector<vector<int> > comp=components(p, n, pos);
vector<vector<int> > adi(n, vector<int> (n, 0));
for(auto c: comp){
solve_component(c, n, p, adi, pos);
}
if(pos){
build(adi);
return 1;
}
return 0;
}
/*signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<vector<int> > p(n, vector<int> (n));
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
cin >> p[i][j];
}
}
cout << construct(p) << "\n";
}*/
# |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
163 ms |
22028 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
163 ms |
22028 KB |
Output is correct |
8 |
Correct |
1 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 |
1100 KB |
Output is correct |
13 |
Correct |
162 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
80 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 |
41 ms |
5776 KB |
Output is correct |
21 |
Correct |
166 ms |
22032 KB |
Output is correct |
22 |
Correct |
161 ms |
21964 KB |
Output is correct |
23 |
Correct |
168 ms |
22024 KB |
Output is correct |
24 |
Correct |
162 ms |
22060 KB |
Output is correct |
25 |
Correct |
76 ms |
12108 KB |
Output is correct |
26 |
Correct |
72 ms |
12048 KB |
Output is correct |
27 |
Correct |
169 ms |
22020 KB |
Output is correct |
28 |
Correct |
162 ms |
22020 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 |
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 |
1108 KB |
Output is correct |
9 |
Correct |
162 ms |
22068 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1108 KB |
Output is correct |
13 |
Correct |
164 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
82 ms |
12164 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 |
40 ms |
5692 KB |
Output is correct |
22 |
Correct |
161 ms |
21964 KB |
Output is correct |
23 |
Correct |
160 ms |
22064 KB |
Output is correct |
24 |
Correct |
174 ms |
22024 KB |
Output is correct |
25 |
Correct |
72 ms |
12160 KB |
Output is correct |
26 |
Correct |
76 ms |
12112 KB |
Output is correct |
27 |
Correct |
160 ms |
22020 KB |
Output is correct |
28 |
Correct |
170 ms |
22020 KB |
Output is correct |
29 |
Correct |
72 ms |
12164 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
46 ms |
5748 KB |
Output is correct |
5 |
Correct |
167 ms |
22016 KB |
Output is correct |
6 |
Correct |
162 ms |
22004 KB |
Output is correct |
7 |
Correct |
176 ms |
22024 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
40 ms |
5768 KB |
Output is correct |
10 |
Correct |
168 ms |
22020 KB |
Output is correct |
11 |
Correct |
168 ms |
22032 KB |
Output is correct |
12 |
Correct |
168 ms |
21976 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
40 ms |
5776 KB |
Output is correct |
17 |
Correct |
163 ms |
22032 KB |
Output is correct |
18 |
Correct |
162 ms |
22036 KB |
Output is correct |
19 |
Correct |
161 ms |
22028 KB |
Output is correct |
20 |
Correct |
162 ms |
22024 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
163 ms |
22028 KB |
Output is correct |
8 |
Correct |
1 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 |
1100 KB |
Output is correct |
13 |
Correct |
162 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
80 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 |
41 ms |
5776 KB |
Output is correct |
21 |
Correct |
166 ms |
22032 KB |
Output is correct |
22 |
Correct |
161 ms |
21964 KB |
Output is correct |
23 |
Correct |
168 ms |
22024 KB |
Output is correct |
24 |
Correct |
162 ms |
22060 KB |
Output is correct |
25 |
Correct |
76 ms |
12108 KB |
Output is correct |
26 |
Correct |
72 ms |
12048 KB |
Output is correct |
27 |
Correct |
169 ms |
22020 KB |
Output is correct |
28 |
Correct |
162 ms |
22020 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 |
1108 KB |
Output is correct |
37 |
Correct |
162 ms |
22068 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1108 KB |
Output is correct |
41 |
Correct |
164 ms |
22020 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
724 KB |
Output is correct |
45 |
Correct |
82 ms |
12164 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 |
40 ms |
5692 KB |
Output is correct |
50 |
Correct |
161 ms |
21964 KB |
Output is correct |
51 |
Correct |
160 ms |
22064 KB |
Output is correct |
52 |
Correct |
174 ms |
22024 KB |
Output is correct |
53 |
Correct |
72 ms |
12160 KB |
Output is correct |
54 |
Correct |
76 ms |
12112 KB |
Output is correct |
55 |
Correct |
160 ms |
22020 KB |
Output is correct |
56 |
Correct |
170 ms |
22020 KB |
Output is correct |
57 |
Correct |
72 ms |
12164 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 |
81 ms |
12044 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 |
Correct |
40 ms |
5680 KB |
Output is correct |
66 |
Correct |
76 ms |
12036 KB |
Output is correct |
67 |
Correct |
73 ms |
12028 KB |
Output is correct |
68 |
Correct |
78 ms |
12036 KB |
Output is correct |
69 |
Correct |
78 ms |
12180 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
163 ms |
22028 KB |
Output is correct |
8 |
Correct |
1 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 |
1100 KB |
Output is correct |
13 |
Correct |
162 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
80 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 |
41 ms |
5776 KB |
Output is correct |
21 |
Correct |
166 ms |
22032 KB |
Output is correct |
22 |
Correct |
161 ms |
21964 KB |
Output is correct |
23 |
Correct |
168 ms |
22024 KB |
Output is correct |
24 |
Correct |
162 ms |
22060 KB |
Output is correct |
25 |
Correct |
76 ms |
12108 KB |
Output is correct |
26 |
Correct |
72 ms |
12048 KB |
Output is correct |
27 |
Correct |
169 ms |
22020 KB |
Output is correct |
28 |
Correct |
162 ms |
22020 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 |
1108 KB |
Output is correct |
37 |
Correct |
162 ms |
22068 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1108 KB |
Output is correct |
41 |
Correct |
164 ms |
22020 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
724 KB |
Output is correct |
45 |
Correct |
82 ms |
12164 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 |
40 ms |
5692 KB |
Output is correct |
50 |
Correct |
161 ms |
21964 KB |
Output is correct |
51 |
Correct |
160 ms |
22064 KB |
Output is correct |
52 |
Correct |
174 ms |
22024 KB |
Output is correct |
53 |
Correct |
72 ms |
12160 KB |
Output is correct |
54 |
Correct |
76 ms |
12112 KB |
Output is correct |
55 |
Correct |
160 ms |
22020 KB |
Output is correct |
56 |
Correct |
170 ms |
22020 KB |
Output is correct |
57 |
Correct |
72 ms |
12164 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 |
46 ms |
5748 KB |
Output is correct |
62 |
Correct |
167 ms |
22016 KB |
Output is correct |
63 |
Correct |
162 ms |
22004 KB |
Output is correct |
64 |
Correct |
176 ms |
22024 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
40 ms |
5768 KB |
Output is correct |
67 |
Correct |
168 ms |
22020 KB |
Output is correct |
68 |
Correct |
168 ms |
22032 KB |
Output is correct |
69 |
Correct |
168 ms |
21976 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
0 ms |
212 KB |
Output is correct |
73 |
Correct |
40 ms |
5776 KB |
Output is correct |
74 |
Correct |
163 ms |
22032 KB |
Output is correct |
75 |
Correct |
162 ms |
22036 KB |
Output is correct |
76 |
Correct |
161 ms |
22028 KB |
Output is correct |
77 |
Correct |
162 ms |
22024 KB |
Output is correct |
78 |
Correct |
0 ms |
212 KB |
Output is correct |
79 |
Correct |
0 ms |
212 KB |
Output is correct |
80 |
Correct |
5 ms |
724 KB |
Output is correct |
81 |
Correct |
81 ms |
12044 KB |
Output is correct |
82 |
Correct |
0 ms |
212 KB |
Output is correct |
83 |
Correct |
0 ms |
212 KB |
Output is correct |
84 |
Correct |
0 ms |
212 KB |
Output is correct |
85 |
Correct |
40 ms |
5680 KB |
Output is correct |
86 |
Correct |
76 ms |
12036 KB |
Output is correct |
87 |
Correct |
73 ms |
12028 KB |
Output is correct |
88 |
Correct |
78 ms |
12036 KB |
Output is correct |
89 |
Correct |
78 ms |
12180 KB |
Output is correct |
90 |
Correct |
0 ms |
212 KB |
Output is correct |
91 |
Correct |
0 ms |
212 KB |
Output is correct |
92 |
Correct |
4 ms |
712 KB |
Output is correct |
93 |
Correct |
82 ms |
12164 KB |
Output is correct |
94 |
Correct |
0 ms |
212 KB |
Output is correct |
95 |
Correct |
1 ms |
212 KB |
Output is correct |
96 |
Correct |
1 ms |
212 KB |
Output is correct |
97 |
Correct |
19 ms |
3704 KB |
Output is correct |
98 |
Correct |
74 ms |
14068 KB |
Output is correct |
99 |
Correct |
75 ms |
14076 KB |
Output is correct |
100 |
Correct |
73 ms |
14068 KB |
Output is correct |
101 |
Correct |
73 ms |
14068 KB |
Output is correct |
102 |
Correct |
78 ms |
13984 KB |
Output is correct |
103 |
Correct |
74 ms |
14028 KB |
Output is correct |
104 |
Correct |
74 ms |
14072 KB |
Output is correct |
105 |
Correct |
87 ms |
14076 KB |
Output is correct |