#include <bits/stdc++.h>
#include "supertrees.h"
#define loop(i, a, b) for(long long i=a;i<b;i++)
#define pool(i, a, b) for(long long i=a-1;i>=b;i--)
#define fore(i, a) for(auto&& i:a)
#define fi first
#define se second
#define ps(a) push_back(a)
#define pb(a) pop_back(a)
#define sc scanf
#define vc vector
#define pa pair<ll, ll>
#define ll int
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define llmax LLONG_MAX/2
#define llmin -LLONG_MAX/2
using namespace std;
#define mn 1010
#define pa pair<ll, ll>
#define ld long double
ll arr[mn], sti[mn], com[mn];
vc<ll> ss[mn], cc[mn];
int construct(vc<vc<int>> p){
ll n=p.size();
loop(i, 0, n) arr[i]=-1, sti[i]=-1, com[i]=-1;
ll cnt=0;
loop(i, 0, n){
loop(j, 0, i){
if(p[i][j]==3) return 0;
if(p[i][j]){
if(arr[i]==-1) arr[i]=arr[j];
else if(arr[i]!=arr[j]) return 0;
}
else{
if(arr[i]==arr[j])return 0;
}
}
if(arr[i]==-1) arr[i]=cnt++;
}
loop(i, 0, n){
loop(j, 0, i){
if(p[i][j]){if(arr[i]!=arr[j])return 0;}
else {if(arr[i]==arr[j])return 0;}
}
}
ll cur=0;
loop(i, 0, n){
loop(j, 0, i){
if(p[i][j]==1){
if(sti[i]==-1) sti[i]=sti[j];
else if(sti[i]!=sti[j]) return 0;
}
else{
if(sti[i]==sti[j])return 0;
}
}
if(sti[i]==-1) sti[i]=cur++;
}
loop(i, 0, n){
loop(j, 0, i){
if(p[i][j]==1){ if(sti[i]!=sti[j])return 0;}
else{ if(sti[i]==sti[j])return 0;}
}
}
loop(i, 0, n) ss[sti[i]].ps(i);
loop(i, 0, n) com[sti[i]]=arr[i];
loop(i, 0, cur) cc[com[i]].ps(i);
vc<int> samp(n, 0);
vc<vc<int>> ans(n, samp);
loop(i, 0, cnt){
if(cc[i].size()==0) return 1;
if(cc[i].size()==1){
vc<ll> u=ss[cc[i][0]];
if(u.size()>1) loop(v, 0, (ll)u.size()-1) ans[u[v]][u[v+1]]=1, ans[u[v+1]][u[v]]=1;
}
else if(cc[i].size()==2) return 0;
else{
fore(t, cc[i]){
vc<ll> u=ss[t];
if(u.size()>1) loop(v, 0, (ll)u.size()-1) ans[u[v]][u[v+1]]=1, ans[u[v+1]][u[v]]=1;
}
loop(t, 0, cc[i].size()){
ans[ss[cc[i][t]][0]][ss[cc[i][((ll)t+1)%((ll)cc[i].size())]][0]]=1;
ans[ss[cc[i][(t+1)%((ll)cc[i].size())]][0]][ss[cc[i][t]][0]]=1;
}
}
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:3:42: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define loop(i, a, b) for(long long i=a;i<b;i++)
......
85 | loop(t, 0, cc[i].size()){
| ~~~~~~~~~~~~~~~~~~
supertrees.cpp:85:13: note: in expansion of macro 'loop'
85 | loop(t, 0, cc[i].size()){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
10 ms |
1388 KB |
Output is correct |
7 |
Correct |
250 ms |
24164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
10 ms |
1388 KB |
Output is correct |
7 |
Correct |
250 ms |
24164 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
360 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
14 ms |
1420 KB |
Output is correct |
13 |
Correct |
241 ms |
24188 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
107 ms |
10340 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
61 ms |
6500 KB |
Output is correct |
21 |
Correct |
244 ms |
24296 KB |
Output is correct |
22 |
Correct |
268 ms |
24164 KB |
Output is correct |
23 |
Correct |
262 ms |
24164 KB |
Output is correct |
24 |
Correct |
242 ms |
24164 KB |
Output is correct |
25 |
Correct |
101 ms |
10212 KB |
Output is correct |
26 |
Correct |
98 ms |
10236 KB |
Output is correct |
27 |
Correct |
252 ms |
24292 KB |
Output is correct |
28 |
Correct |
243 ms |
24292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
10 ms |
1388 KB |
Output is correct |
9 |
Correct |
238 ms |
24192 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
10 ms |
1388 KB |
Output is correct |
13 |
Correct |
239 ms |
24164 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
748 KB |
Output is correct |
17 |
Correct |
105 ms |
10216 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
508 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
62 ms |
6368 KB |
Output is correct |
22 |
Correct |
249 ms |
24164 KB |
Output is correct |
23 |
Correct |
239 ms |
24164 KB |
Output is correct |
24 |
Correct |
248 ms |
24420 KB |
Output is correct |
25 |
Correct |
116 ms |
14224 KB |
Output is correct |
26 |
Correct |
102 ms |
10212 KB |
Output is correct |
27 |
Correct |
242 ms |
24184 KB |
Output is correct |
28 |
Correct |
249 ms |
24164 KB |
Output is correct |
29 |
Correct |
108 ms |
14308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
60 ms |
6500 KB |
Output is correct |
5 |
Correct |
243 ms |
24164 KB |
Output is correct |
6 |
Correct |
244 ms |
24164 KB |
Output is correct |
7 |
Correct |
250 ms |
24164 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
61 ms |
6372 KB |
Output is correct |
10 |
Correct |
239 ms |
24164 KB |
Output is correct |
11 |
Correct |
244 ms |
24164 KB |
Output is correct |
12 |
Correct |
250 ms |
24292 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
62 ms |
6500 KB |
Output is correct |
17 |
Correct |
245 ms |
24164 KB |
Output is correct |
18 |
Correct |
246 ms |
24164 KB |
Output is correct |
19 |
Correct |
241 ms |
24164 KB |
Output is correct |
20 |
Correct |
240 ms |
24160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
10 ms |
1388 KB |
Output is correct |
7 |
Correct |
250 ms |
24164 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
360 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
14 ms |
1420 KB |
Output is correct |
13 |
Correct |
241 ms |
24188 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
107 ms |
10340 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
61 ms |
6500 KB |
Output is correct |
21 |
Correct |
244 ms |
24296 KB |
Output is correct |
22 |
Correct |
268 ms |
24164 KB |
Output is correct |
23 |
Correct |
262 ms |
24164 KB |
Output is correct |
24 |
Correct |
242 ms |
24164 KB |
Output is correct |
25 |
Correct |
101 ms |
10212 KB |
Output is correct |
26 |
Correct |
98 ms |
10236 KB |
Output is correct |
27 |
Correct |
252 ms |
24292 KB |
Output is correct |
28 |
Correct |
243 ms |
24292 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
10 ms |
1388 KB |
Output is correct |
37 |
Correct |
238 ms |
24192 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
10 ms |
1388 KB |
Output is correct |
41 |
Correct |
239 ms |
24164 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
5 ms |
748 KB |
Output is correct |
45 |
Correct |
105 ms |
10216 KB |
Output is correct |
46 |
Correct |
1 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
508 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
62 ms |
6368 KB |
Output is correct |
50 |
Correct |
249 ms |
24164 KB |
Output is correct |
51 |
Correct |
239 ms |
24164 KB |
Output is correct |
52 |
Correct |
248 ms |
24420 KB |
Output is correct |
53 |
Correct |
116 ms |
14224 KB |
Output is correct |
54 |
Correct |
102 ms |
10212 KB |
Output is correct |
55 |
Correct |
242 ms |
24184 KB |
Output is correct |
56 |
Correct |
249 ms |
24164 KB |
Output is correct |
57 |
Correct |
108 ms |
14308 KB |
Output is correct |
58 |
Correct |
1 ms |
428 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
5 ms |
748 KB |
Output is correct |
61 |
Correct |
104 ms |
10336 KB |
Output is correct |
62 |
Correct |
1 ms |
364 KB |
Output is correct |
63 |
Correct |
1 ms |
364 KB |
Output is correct |
64 |
Correct |
1 ms |
364 KB |
Output is correct |
65 |
Correct |
62 ms |
6372 KB |
Output is correct |
66 |
Correct |
101 ms |
10340 KB |
Output is correct |
67 |
Correct |
99 ms |
10260 KB |
Output is correct |
68 |
Correct |
104 ms |
10212 KB |
Output is correct |
69 |
Correct |
102 ms |
14308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
10 ms |
1388 KB |
Output is correct |
7 |
Correct |
250 ms |
24164 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
360 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
14 ms |
1420 KB |
Output is correct |
13 |
Correct |
241 ms |
24188 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
107 ms |
10340 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
61 ms |
6500 KB |
Output is correct |
21 |
Correct |
244 ms |
24296 KB |
Output is correct |
22 |
Correct |
268 ms |
24164 KB |
Output is correct |
23 |
Correct |
262 ms |
24164 KB |
Output is correct |
24 |
Correct |
242 ms |
24164 KB |
Output is correct |
25 |
Correct |
101 ms |
10212 KB |
Output is correct |
26 |
Correct |
98 ms |
10236 KB |
Output is correct |
27 |
Correct |
252 ms |
24292 KB |
Output is correct |
28 |
Correct |
243 ms |
24292 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
10 ms |
1388 KB |
Output is correct |
37 |
Correct |
238 ms |
24192 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
10 ms |
1388 KB |
Output is correct |
41 |
Correct |
239 ms |
24164 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
5 ms |
748 KB |
Output is correct |
45 |
Correct |
105 ms |
10216 KB |
Output is correct |
46 |
Correct |
1 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
508 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
62 ms |
6368 KB |
Output is correct |
50 |
Correct |
249 ms |
24164 KB |
Output is correct |
51 |
Correct |
239 ms |
24164 KB |
Output is correct |
52 |
Correct |
248 ms |
24420 KB |
Output is correct |
53 |
Correct |
116 ms |
14224 KB |
Output is correct |
54 |
Correct |
102 ms |
10212 KB |
Output is correct |
55 |
Correct |
242 ms |
24184 KB |
Output is correct |
56 |
Correct |
249 ms |
24164 KB |
Output is correct |
57 |
Correct |
108 ms |
14308 KB |
Output is correct |
58 |
Correct |
1 ms |
364 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
1 ms |
364 KB |
Output is correct |
61 |
Correct |
60 ms |
6500 KB |
Output is correct |
62 |
Correct |
243 ms |
24164 KB |
Output is correct |
63 |
Correct |
244 ms |
24164 KB |
Output is correct |
64 |
Correct |
250 ms |
24164 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Correct |
61 ms |
6372 KB |
Output is correct |
67 |
Correct |
239 ms |
24164 KB |
Output is correct |
68 |
Correct |
244 ms |
24164 KB |
Output is correct |
69 |
Correct |
250 ms |
24292 KB |
Output is correct |
70 |
Correct |
1 ms |
364 KB |
Output is correct |
71 |
Correct |
1 ms |
364 KB |
Output is correct |
72 |
Correct |
1 ms |
364 KB |
Output is correct |
73 |
Correct |
62 ms |
6500 KB |
Output is correct |
74 |
Correct |
245 ms |
24164 KB |
Output is correct |
75 |
Correct |
246 ms |
24164 KB |
Output is correct |
76 |
Correct |
241 ms |
24164 KB |
Output is correct |
77 |
Correct |
240 ms |
24160 KB |
Output is correct |
78 |
Correct |
1 ms |
428 KB |
Output is correct |
79 |
Correct |
1 ms |
364 KB |
Output is correct |
80 |
Correct |
5 ms |
748 KB |
Output is correct |
81 |
Correct |
104 ms |
10336 KB |
Output is correct |
82 |
Correct |
1 ms |
364 KB |
Output is correct |
83 |
Correct |
1 ms |
364 KB |
Output is correct |
84 |
Correct |
1 ms |
364 KB |
Output is correct |
85 |
Correct |
62 ms |
6372 KB |
Output is correct |
86 |
Correct |
101 ms |
10340 KB |
Output is correct |
87 |
Correct |
99 ms |
10260 KB |
Output is correct |
88 |
Correct |
104 ms |
10212 KB |
Output is correct |
89 |
Correct |
102 ms |
14308 KB |
Output is correct |
90 |
Correct |
1 ms |
364 KB |
Output is correct |
91 |
Correct |
1 ms |
364 KB |
Output is correct |
92 |
Correct |
5 ms |
748 KB |
Output is correct |
93 |
Correct |
102 ms |
10212 KB |
Output is correct |
94 |
Correct |
1 ms |
364 KB |
Output is correct |
95 |
Correct |
1 ms |
364 KB |
Output is correct |
96 |
Correct |
1 ms |
364 KB |
Output is correct |
97 |
Correct |
25 ms |
2916 KB |
Output is correct |
98 |
Correct |
102 ms |
10260 KB |
Output is correct |
99 |
Correct |
100 ms |
10212 KB |
Output is correct |
100 |
Correct |
100 ms |
10212 KB |
Output is correct |
101 |
Correct |
97 ms |
10212 KB |
Output is correct |
102 |
Correct |
96 ms |
10232 KB |
Output is correct |
103 |
Correct |
102 ms |
10212 KB |
Output is correct |
104 |
Correct |
102 ms |
10212 KB |
Output is correct |
105 |
Correct |
108 ms |
10212 KB |
Output is correct |