#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"
const int N = 2e5 + 9 , mod = 1e9 + 7;
ll a[N] , b[N] , dp[N];
//int press(string a){}
int construct(vector<vector<int>> v){
ll i , j , l , r , s = 0, f , n , m , x , y , k;
n = v.size();
vector<vector<int>>c(n);
for(i = 0; i < n; i++)
c[i].resize(n);
for(i = 0; i < n; i++){
if(b[i] != 0)
continue;
vector<pair<int,pair<int,int>>>vc;
vector<int>v1 , v2 , v3;
for(j = 0; j < n; j++)
if(v[i][j] != 0)
b[j] = 1 , v1.pb(j);
l = r = 0;
for(x = 0; x < v1.size(); x++){
if(b[v1[x]] != 2)
b[v1[x]] = 3;
f = v1[x];
vector<int>vv;
vv.pb(f);
for(y = 0; y < v1.size(); y++){
vc.pb({v[v1[x]][v1[y]] , {v1[x] , v1[y]}});
if(v[v1[x]][v1[y]] == 2)
l = 1;
else if(v[v1[x]][v1[y]] == 3)
r = 1;
else if(b[v1[x]] == 3 && x != y){
if(b[v1[y]] == 2)
return 0;
c[v1[y]][f] = c[f][v1[y]] = 1;
b[v1[y]] = 2;
f = v1[y];
vv.pb(f);
}
}
if(b[v1[x]] == 3)
for(auto to : vv){
s= f = 0;
for(auto to1:vv)
if(v[to][to1] != 1)
return 0;
for(j = 0; j < n; j++)
if(v[to][j] == 1)
s++;
else if(v[to][j])
f++;
if(s != vv.size() || s + f != v1.size())
return 0;
}
}
sort(all(vc));
if(v1.size() == 1)
continue;
if((l == 1 && r == 1) || vc.front().fi == 0)
return 0;
set<int>st;
for(auto to : v1){
st.insert(to);
if(b[to] == 3)
v2.pb(to);
else
v3.pb(to);
}
if(l + r > 0){
if(v2.size() <= vc.back().fi){
return 0;
}
f = v2.back();
for(auto to : v2)
c[f][to] = c[to][f] = 1 , f = to;
if(vc.back().fi == 3)
c[v2[0]][v2[2]] = c[v2[2]][v2[0]] = 1;
}
for(auto to : v1){
ll L = 0 ,R = 0 , s =0;
for(j = 0; j < n ; j++)
if(v[to][j] != 0){
if(st.find(j) == st.end())
return 0;
s++;
if(to == j)
continue;
if(v[to][j] == 2)
L = 1;
else if(v[to][j] == 3)
R = 1;
}
if((L > l) || (R > r) || s != v1.size())
return 0;
}
}
// for(i = 0; i < n; i++){
// for(j = 0; j < n; j++)
// cout<<c[i][j]<<" ";
// cout<<"\n";
// }
build(c);
return 1;
}
/*
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cout<<construct({{1, 1, 2, 2}, {1, 1, 2, 2}, {2, 2, 1, 2}, {2, 2, 2, 1}});
}*/
// Author : حسن
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:41:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(x = 0; x < v1.size(); x++){
| ~~^~~~~~~~~~~
supertrees.cpp:47:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(y = 0; y < v1.size(); y++){
| ~~^~~~~~~~~~~
supertrees.cpp:74:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | if(s != vv.size() || s + f != v1.size())
| ~~^~~~~~~~~~~~
supertrees.cpp:74:44: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | if(s != vv.size() || s + f != v1.size())
| ~~~~~~^~~~~~~~~~~~
supertrees.cpp:92:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
92 | if(v2.size() <= vc.back().fi){
| ^
supertrees.cpp:115:40: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | if((L > l) || (R > r) || s != v1.size())
| ~~^~~~~~~~~~~~
supertrees.cpp:27:40: warning: unused variable 'm' [-Wunused-variable]
27 | ll i , j , l , r , s = 0, f , n , m , x , y , k;
| ^
supertrees.cpp:27:52: warning: unused variable 'k' [-Wunused-variable]
27 | ll i , j , l , r , s = 0, f , n , m , x , y , k;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
444 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1880 KB |
Output is correct |
7 |
Correct |
193 ms |
28000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
444 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1880 KB |
Output is correct |
7 |
Correct |
193 ms |
28000 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
444 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
117 ms |
23380 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
57 ms |
13520 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
31 ms |
6236 KB |
Output is correct |
21 |
Correct |
128 ms |
23356 KB |
Output is correct |
22 |
Correct |
113 ms |
23380 KB |
Output is correct |
23 |
Correct |
156 ms |
23260 KB |
Output is correct |
24 |
Correct |
113 ms |
23280 KB |
Output is correct |
25 |
Correct |
68 ms |
13880 KB |
Output is correct |
26 |
Correct |
51 ms |
13392 KB |
Output is correct |
27 |
Correct |
144 ms |
23332 KB |
Output is correct |
28 |
Correct |
114 ms |
23452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
5 ms |
1200 KB |
Output is correct |
9 |
Correct |
111 ms |
23256 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
444 KB |
Output is correct |
12 |
Correct |
13 ms |
1704 KB |
Output is correct |
13 |
Correct |
273 ms |
26624 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
61 ms |
13536 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
42 ms |
6324 KB |
Output is correct |
22 |
Correct |
144 ms |
23248 KB |
Output is correct |
23 |
Correct |
123 ms |
23376 KB |
Output is correct |
24 |
Correct |
214 ms |
24372 KB |
Output is correct |
25 |
Correct |
58 ms |
13488 KB |
Output is correct |
26 |
Correct |
62 ms |
13844 KB |
Output is correct |
27 |
Correct |
149 ms |
23308 KB |
Output is correct |
28 |
Correct |
190 ms |
23428 KB |
Output is correct |
29 |
Correct |
61 ms |
13396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
444 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
29 ms |
6412 KB |
Output is correct |
5 |
Correct |
122 ms |
23356 KB |
Output is correct |
6 |
Correct |
119 ms |
23464 KB |
Output is correct |
7 |
Correct |
149 ms |
23380 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
30 ms |
6280 KB |
Output is correct |
10 |
Correct |
130 ms |
23316 KB |
Output is correct |
11 |
Correct |
120 ms |
23248 KB |
Output is correct |
12 |
Correct |
210 ms |
24396 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
33 ms |
6248 KB |
Output is correct |
17 |
Correct |
123 ms |
23384 KB |
Output is correct |
18 |
Correct |
147 ms |
23396 KB |
Output is correct |
19 |
Correct |
124 ms |
23376 KB |
Output is correct |
20 |
Correct |
173 ms |
23424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
444 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1880 KB |
Output is correct |
7 |
Correct |
193 ms |
28000 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
444 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
117 ms |
23380 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
57 ms |
13520 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
31 ms |
6236 KB |
Output is correct |
21 |
Correct |
128 ms |
23356 KB |
Output is correct |
22 |
Correct |
113 ms |
23380 KB |
Output is correct |
23 |
Correct |
156 ms |
23260 KB |
Output is correct |
24 |
Correct |
113 ms |
23280 KB |
Output is correct |
25 |
Correct |
68 ms |
13880 KB |
Output is correct |
26 |
Correct |
51 ms |
13392 KB |
Output is correct |
27 |
Correct |
144 ms |
23332 KB |
Output is correct |
28 |
Correct |
114 ms |
23452 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
5 ms |
1200 KB |
Output is correct |
37 |
Correct |
111 ms |
23256 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
444 KB |
Output is correct |
40 |
Correct |
13 ms |
1704 KB |
Output is correct |
41 |
Correct |
273 ms |
26624 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
61 ms |
13536 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
42 ms |
6324 KB |
Output is correct |
50 |
Correct |
144 ms |
23248 KB |
Output is correct |
51 |
Correct |
123 ms |
23376 KB |
Output is correct |
52 |
Correct |
214 ms |
24372 KB |
Output is correct |
53 |
Correct |
58 ms |
13488 KB |
Output is correct |
54 |
Correct |
62 ms |
13844 KB |
Output is correct |
55 |
Correct |
149 ms |
23308 KB |
Output is correct |
56 |
Correct |
190 ms |
23428 KB |
Output is correct |
57 |
Correct |
61 ms |
13396 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
3 ms |
860 KB |
Output is correct |
61 |
Correct |
55 ms |
13396 KB |
Output is correct |
62 |
Correct |
0 ms |
344 KB |
Output is correct |
63 |
Correct |
0 ms |
348 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
29 ms |
6228 KB |
Output is correct |
66 |
Correct |
53 ms |
13644 KB |
Output is correct |
67 |
Correct |
55 ms |
13856 KB |
Output is correct |
68 |
Correct |
53 ms |
13392 KB |
Output is correct |
69 |
Correct |
50 ms |
13428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
444 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1880 KB |
Output is correct |
7 |
Correct |
193 ms |
28000 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
444 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
117 ms |
23380 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
57 ms |
13520 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
31 ms |
6236 KB |
Output is correct |
21 |
Correct |
128 ms |
23356 KB |
Output is correct |
22 |
Correct |
113 ms |
23380 KB |
Output is correct |
23 |
Correct |
156 ms |
23260 KB |
Output is correct |
24 |
Correct |
113 ms |
23280 KB |
Output is correct |
25 |
Correct |
68 ms |
13880 KB |
Output is correct |
26 |
Correct |
51 ms |
13392 KB |
Output is correct |
27 |
Correct |
144 ms |
23332 KB |
Output is correct |
28 |
Correct |
114 ms |
23452 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
5 ms |
1200 KB |
Output is correct |
37 |
Correct |
111 ms |
23256 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
444 KB |
Output is correct |
40 |
Correct |
13 ms |
1704 KB |
Output is correct |
41 |
Correct |
273 ms |
26624 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
61 ms |
13536 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
42 ms |
6324 KB |
Output is correct |
50 |
Correct |
144 ms |
23248 KB |
Output is correct |
51 |
Correct |
123 ms |
23376 KB |
Output is correct |
52 |
Correct |
214 ms |
24372 KB |
Output is correct |
53 |
Correct |
58 ms |
13488 KB |
Output is correct |
54 |
Correct |
62 ms |
13844 KB |
Output is correct |
55 |
Correct |
149 ms |
23308 KB |
Output is correct |
56 |
Correct |
190 ms |
23428 KB |
Output is correct |
57 |
Correct |
61 ms |
13396 KB |
Output is correct |
58 |
Correct |
0 ms |
444 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
29 ms |
6412 KB |
Output is correct |
62 |
Correct |
122 ms |
23356 KB |
Output is correct |
63 |
Correct |
119 ms |
23464 KB |
Output is correct |
64 |
Correct |
149 ms |
23380 KB |
Output is correct |
65 |
Correct |
1 ms |
348 KB |
Output is correct |
66 |
Correct |
30 ms |
6280 KB |
Output is correct |
67 |
Correct |
130 ms |
23316 KB |
Output is correct |
68 |
Correct |
120 ms |
23248 KB |
Output is correct |
69 |
Correct |
210 ms |
24396 KB |
Output is correct |
70 |
Correct |
0 ms |
348 KB |
Output is correct |
71 |
Correct |
0 ms |
344 KB |
Output is correct |
72 |
Correct |
0 ms |
348 KB |
Output is correct |
73 |
Correct |
33 ms |
6248 KB |
Output is correct |
74 |
Correct |
123 ms |
23384 KB |
Output is correct |
75 |
Correct |
147 ms |
23396 KB |
Output is correct |
76 |
Correct |
124 ms |
23376 KB |
Output is correct |
77 |
Correct |
173 ms |
23424 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
1 ms |
348 KB |
Output is correct |
80 |
Correct |
3 ms |
860 KB |
Output is correct |
81 |
Correct |
55 ms |
13396 KB |
Output is correct |
82 |
Correct |
0 ms |
344 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |
84 |
Correct |
0 ms |
348 KB |
Output is correct |
85 |
Correct |
29 ms |
6228 KB |
Output is correct |
86 |
Correct |
53 ms |
13644 KB |
Output is correct |
87 |
Correct |
55 ms |
13856 KB |
Output is correct |
88 |
Correct |
53 ms |
13392 KB |
Output is correct |
89 |
Correct |
50 ms |
13428 KB |
Output is correct |
90 |
Correct |
1 ms |
344 KB |
Output is correct |
91 |
Correct |
0 ms |
348 KB |
Output is correct |
92 |
Correct |
2 ms |
860 KB |
Output is correct |
93 |
Correct |
59 ms |
13396 KB |
Output is correct |
94 |
Correct |
0 ms |
600 KB |
Output is correct |
95 |
Correct |
0 ms |
348 KB |
Output is correct |
96 |
Correct |
0 ms |
600 KB |
Output is correct |
97 |
Correct |
13 ms |
3672 KB |
Output is correct |
98 |
Correct |
52 ms |
13856 KB |
Output is correct |
99 |
Correct |
68 ms |
13880 KB |
Output is correct |
100 |
Correct |
69 ms |
13616 KB |
Output is correct |
101 |
Correct |
78 ms |
13576 KB |
Output is correct |
102 |
Incorrect |
264 ms |
27324 KB |
Answer gives possible 1 while actual possible 0 |
103 |
Halted |
0 ms |
0 KB |
- |