#include <bits/stdc++.h>
#include "supertrees.h"
#define all(a) a.begin(),a.end()
using namespace std;
const int mxn= 1e3+1 ;
vector<int> adj[mxn] , adjj[mxn] , one , mn ;
void dfs(int i , vector<int>& a ){
a[i]=1 ;
for(int& x : adj[i]){
if(a[x]) continue ;
dfs(x,a) ;
}
}
int cnt = 0 ;
void dfss(int i , vector<int>& a){
a[i] = 1 ;
++cnt ;
if(adjj[i].size()==1) one.push_back(i) ;
for(int& x : adjj[i]){
if(a[x]) continue ;
dfss(x,a) ;
}
}
vector<vector<int>> ppp;
bool check(int i , vector<int>& a){
a[i] =1 ;
for(int j=0;j<mn.size();j++){
if(ppp[i][j]==2&&mn[j]!=2) return 1 ;
if(mn[j]==2&&ppp[i][j]!=2) return 1 ;
}
bool b = 0 ;
for(int& x : adj[i]){
if(a[x]) continue ;
b|=check(x,a) ;
}
return b ;
}
int construct(vector<vector<int>> p){
ppp= p ;
int n =p.size() ;
vector<int> the(n) ;
for(int i=0;i<n;i++){
bool flg = 0 ;
vector<int> x=p[i] ;
for(int j=0;j<i;j++){
if(x[j]==1){
adj[i].push_back(j) ;
flg = 1 ;
break ;
}
}
if(flg) continue ;
//cout <<i << endl ;
the[i] =1 ;
for(int j=i+1;j<n;j++) if(x[j]==1) adj[i].push_back(j) ;
}
for(int i=0;i<n;i++){
vector<int> vis(n) ;
dfs(i,vis) ;
for(int j=0;j<n;j++){
if(vis[j]==1&&p[i][j]==1) continue ;
if(vis[j]==0&&p[i][j]==0) continue ;
if(p[i][j]==2&&vis[j]==0) continue ;
return 0 ;
}
}
for(int i=0;i<n;i++){
if(the[i]==0) continue ;
for(int j=i-1;j>-1;j--){
if(the[j]==0) continue ;
if(p[i][j]==2){
adjj[i].push_back(j) ;
break ;
}
}
for(int j=i+1;j<n;j++){
if(the[j]==0) continue ;
if(p[i][j]==2){
adjj[i].push_back(j) ;
break ;
}
}
}
map<vector<int>,int> pp ;
for(int i=0;i<n;i++){
if(the[i]==0) continue ;
// if(vis[i]) continue ;
vector<int> vis(n);
one.erase(one.begin(),one.end()) ;
cnt= 0 ;
dfss(i,vis) ;
if(cnt==2) return 0 ;
sort(all(one)) ;
for(int j=0;j<n;j++){
if(i==j) continue ;
/*if(vis[j]&&p[i][j]==0)return 0 ;
if(vis[j]==0&&p[i][j]) return 0 ; */
if(the[j]==0) continue ;
if(vis[j]==1&&p[i][j]==2) continue ;
if(vis[j]==0&&p[i][j]==0) continue ;
if(vis[j]==0&&p[i][j]==1) continue ;
return 0 ;
//cout << i << " " << j << endl ;
}
if(one.size()==0) continue ;
if(one.size()==1) continue ;
if(one.size()>2) return 0 ;
if(pp[{one[0],one[1]}]) continue ;
pp[{one[0],one[1]}]=1 ;
adjj[one[1]].push_back(one[0]) ;
adjj[one[0]].push_back(one[1]) ;
}
vector<int> viss(n) ;
for(int i=0;i<n;i++){
if(viss[i]==1) continue ;
mn = p[i] ;
bool f = check(i,viss) ;
if(f) return 0 ;
}
vector<vector<int>> ans ;
for(int i=0;i<n;i++) for(int& x : adjj[i]) adj[i].push_back(x) ;
for(int i=0;i<n;i++){
vector<int> row(n) ;
for(int& x : adj[i]) row[x]= 1 ;
ans.push_back(row) ;
}
build(ans) ;
return 1 ;
}
Compilation message
supertrees.cpp: In function 'bool check(int, std::vector<int>&)':
supertrees.cpp:27:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int j=0;j<mn.size();j++){
| ~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
248 ms |
26104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
248 ms |
26104 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1408 KB |
Output is correct |
13 |
Correct |
244 ms |
26232 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
896 KB |
Output is correct |
17 |
Correct |
108 ms |
12280 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
60 ms |
6904 KB |
Output is correct |
21 |
Correct |
241 ms |
26104 KB |
Output is correct |
22 |
Correct |
234 ms |
26104 KB |
Output is correct |
23 |
Correct |
254 ms |
26232 KB |
Output is correct |
24 |
Correct |
240 ms |
26232 KB |
Output is correct |
25 |
Correct |
98 ms |
12408 KB |
Output is correct |
26 |
Correct |
94 ms |
12412 KB |
Output is correct |
27 |
Correct |
258 ms |
26120 KB |
Output is correct |
28 |
Correct |
240 ms |
26236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
10 ms |
1408 KB |
Output is correct |
9 |
Correct |
235 ms |
26248 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
263 ms |
26372 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
896 KB |
Output is correct |
17 |
Correct |
107 ms |
12284 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
60 ms |
6904 KB |
Output is correct |
22 |
Correct |
242 ms |
26104 KB |
Output is correct |
23 |
Correct |
238 ms |
26232 KB |
Output is correct |
24 |
Correct |
262 ms |
26360 KB |
Output is correct |
25 |
Correct |
101 ms |
12280 KB |
Output is correct |
26 |
Correct |
100 ms |
12280 KB |
Output is correct |
27 |
Correct |
242 ms |
26232 KB |
Output is correct |
28 |
Correct |
262 ms |
26232 KB |
Output is correct |
29 |
Correct |
100 ms |
12152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
59 ms |
7032 KB |
Output is correct |
5 |
Correct |
235 ms |
26104 KB |
Output is correct |
6 |
Correct |
238 ms |
26104 KB |
Output is correct |
7 |
Correct |
250 ms |
26236 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
64 ms |
6904 KB |
Output is correct |
10 |
Correct |
242 ms |
26232 KB |
Output is correct |
11 |
Correct |
238 ms |
26232 KB |
Output is correct |
12 |
Correct |
256 ms |
26232 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
60 ms |
6904 KB |
Output is correct |
17 |
Correct |
249 ms |
26104 KB |
Output is correct |
18 |
Correct |
245 ms |
26360 KB |
Output is correct |
19 |
Correct |
245 ms |
26104 KB |
Output is correct |
20 |
Correct |
244 ms |
26384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
248 ms |
26104 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1408 KB |
Output is correct |
13 |
Correct |
244 ms |
26232 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
896 KB |
Output is correct |
17 |
Correct |
108 ms |
12280 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
60 ms |
6904 KB |
Output is correct |
21 |
Correct |
241 ms |
26104 KB |
Output is correct |
22 |
Correct |
234 ms |
26104 KB |
Output is correct |
23 |
Correct |
254 ms |
26232 KB |
Output is correct |
24 |
Correct |
240 ms |
26232 KB |
Output is correct |
25 |
Correct |
98 ms |
12408 KB |
Output is correct |
26 |
Correct |
94 ms |
12412 KB |
Output is correct |
27 |
Correct |
258 ms |
26120 KB |
Output is correct |
28 |
Correct |
240 ms |
26236 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
10 ms |
1408 KB |
Output is correct |
37 |
Correct |
235 ms |
26248 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
1408 KB |
Output is correct |
41 |
Correct |
263 ms |
26372 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
1 ms |
384 KB |
Output is correct |
44 |
Correct |
5 ms |
896 KB |
Output is correct |
45 |
Correct |
107 ms |
12284 KB |
Output is correct |
46 |
Correct |
1 ms |
384 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
512 KB |
Output is correct |
49 |
Correct |
60 ms |
6904 KB |
Output is correct |
50 |
Correct |
242 ms |
26104 KB |
Output is correct |
51 |
Correct |
238 ms |
26232 KB |
Output is correct |
52 |
Correct |
262 ms |
26360 KB |
Output is correct |
53 |
Correct |
101 ms |
12280 KB |
Output is correct |
54 |
Correct |
100 ms |
12280 KB |
Output is correct |
55 |
Correct |
242 ms |
26232 KB |
Output is correct |
56 |
Correct |
262 ms |
26232 KB |
Output is correct |
57 |
Correct |
100 ms |
12152 KB |
Output is correct |
58 |
Correct |
1 ms |
416 KB |
Output is correct |
59 |
Correct |
1 ms |
384 KB |
Output is correct |
60 |
Correct |
5 ms |
896 KB |
Output is correct |
61 |
Correct |
106 ms |
12192 KB |
Output is correct |
62 |
Correct |
1 ms |
384 KB |
Output is correct |
63 |
Correct |
1 ms |
384 KB |
Output is correct |
64 |
Correct |
1 ms |
384 KB |
Output is correct |
65 |
Correct |
65 ms |
7032 KB |
Output is correct |
66 |
Correct |
100 ms |
12280 KB |
Output is correct |
67 |
Correct |
100 ms |
12152 KB |
Output is correct |
68 |
Correct |
99 ms |
12408 KB |
Output is correct |
69 |
Correct |
102 ms |
12152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
248 ms |
26104 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1408 KB |
Output is correct |
13 |
Correct |
244 ms |
26232 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
896 KB |
Output is correct |
17 |
Correct |
108 ms |
12280 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
60 ms |
6904 KB |
Output is correct |
21 |
Correct |
241 ms |
26104 KB |
Output is correct |
22 |
Correct |
234 ms |
26104 KB |
Output is correct |
23 |
Correct |
254 ms |
26232 KB |
Output is correct |
24 |
Correct |
240 ms |
26232 KB |
Output is correct |
25 |
Correct |
98 ms |
12408 KB |
Output is correct |
26 |
Correct |
94 ms |
12412 KB |
Output is correct |
27 |
Correct |
258 ms |
26120 KB |
Output is correct |
28 |
Correct |
240 ms |
26236 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
10 ms |
1408 KB |
Output is correct |
37 |
Correct |
235 ms |
26248 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
1408 KB |
Output is correct |
41 |
Correct |
263 ms |
26372 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
1 ms |
384 KB |
Output is correct |
44 |
Correct |
5 ms |
896 KB |
Output is correct |
45 |
Correct |
107 ms |
12284 KB |
Output is correct |
46 |
Correct |
1 ms |
384 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
512 KB |
Output is correct |
49 |
Correct |
60 ms |
6904 KB |
Output is correct |
50 |
Correct |
242 ms |
26104 KB |
Output is correct |
51 |
Correct |
238 ms |
26232 KB |
Output is correct |
52 |
Correct |
262 ms |
26360 KB |
Output is correct |
53 |
Correct |
101 ms |
12280 KB |
Output is correct |
54 |
Correct |
100 ms |
12280 KB |
Output is correct |
55 |
Correct |
242 ms |
26232 KB |
Output is correct |
56 |
Correct |
262 ms |
26232 KB |
Output is correct |
57 |
Correct |
100 ms |
12152 KB |
Output is correct |
58 |
Correct |
1 ms |
384 KB |
Output is correct |
59 |
Correct |
0 ms |
384 KB |
Output is correct |
60 |
Correct |
1 ms |
384 KB |
Output is correct |
61 |
Correct |
59 ms |
7032 KB |
Output is correct |
62 |
Correct |
235 ms |
26104 KB |
Output is correct |
63 |
Correct |
238 ms |
26104 KB |
Output is correct |
64 |
Correct |
250 ms |
26236 KB |
Output is correct |
65 |
Correct |
1 ms |
384 KB |
Output is correct |
66 |
Correct |
64 ms |
6904 KB |
Output is correct |
67 |
Correct |
242 ms |
26232 KB |
Output is correct |
68 |
Correct |
238 ms |
26232 KB |
Output is correct |
69 |
Correct |
256 ms |
26232 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |
71 |
Correct |
1 ms |
384 KB |
Output is correct |
72 |
Correct |
1 ms |
512 KB |
Output is correct |
73 |
Correct |
60 ms |
6904 KB |
Output is correct |
74 |
Correct |
249 ms |
26104 KB |
Output is correct |
75 |
Correct |
245 ms |
26360 KB |
Output is correct |
76 |
Correct |
245 ms |
26104 KB |
Output is correct |
77 |
Correct |
244 ms |
26384 KB |
Output is correct |
78 |
Correct |
1 ms |
416 KB |
Output is correct |
79 |
Correct |
1 ms |
384 KB |
Output is correct |
80 |
Correct |
5 ms |
896 KB |
Output is correct |
81 |
Correct |
106 ms |
12192 KB |
Output is correct |
82 |
Correct |
1 ms |
384 KB |
Output is correct |
83 |
Correct |
1 ms |
384 KB |
Output is correct |
84 |
Correct |
1 ms |
384 KB |
Output is correct |
85 |
Correct |
65 ms |
7032 KB |
Output is correct |
86 |
Correct |
100 ms |
12280 KB |
Output is correct |
87 |
Correct |
100 ms |
12152 KB |
Output is correct |
88 |
Correct |
99 ms |
12408 KB |
Output is correct |
89 |
Correct |
102 ms |
12152 KB |
Output is correct |
90 |
Correct |
1 ms |
384 KB |
Output is correct |
91 |
Correct |
1 ms |
384 KB |
Output is correct |
92 |
Correct |
5 ms |
896 KB |
Output is correct |
93 |
Correct |
113 ms |
12408 KB |
Output is correct |
94 |
Correct |
1 ms |
384 KB |
Output is correct |
95 |
Correct |
1 ms |
384 KB |
Output is correct |
96 |
Correct |
1 ms |
384 KB |
Output is correct |
97 |
Correct |
24 ms |
3328 KB |
Output is correct |
98 |
Correct |
117 ms |
12152 KB |
Output is correct |
99 |
Correct |
96 ms |
12280 KB |
Output is correct |
100 |
Correct |
94 ms |
12280 KB |
Output is correct |
101 |
Correct |
95 ms |
12152 KB |
Output is correct |
102 |
Correct |
106 ms |
12156 KB |
Output is correct |
103 |
Correct |
110 ms |
12412 KB |
Output is correct |
104 |
Correct |
101 ms |
12280 KB |
Output is correct |
105 |
Correct |
106 ms |
12280 KB |
Output is correct |