#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define pb emplace_back
#define fi first
#define se second
template<class T> void out(T a){cout<<a<<endl;}
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
const ll inf=1001001001001001001;
#include "supertrees.h"
int construct(vector<vector<int>> v){
ll n=v.size();
rep(i,n)rep(j,n)if(v[i][j]==3)return 0;
vi gr1(n,-1);
ll c1=0;
rep(i,n)if(gr1[i]==-1){
queue<ll> que;
que.push(i);
gr1[i]=c1;
while(!que.empty()){
ll t=que.front();que.pop();
rep(j,n)if(v[j][t]>0&&gr1[j]==-1){
gr1[j]=c1;que.push(j);
}
}
c1++;
}
rep(i,n)rep(j,i)if(v[i][j]==0&&gr1[i]==gr1[j])return 0;
rep(i,n)rep(j,i)if(v[i][j]>0&&gr1[i]!=gr1[j])return 0;
vi gr2(n,-1);
ll c2=0;
vvi al1(c1);
rep(i,n)if(gr2[i]==-1){
al1[gr1[i]].pb(i);
queue<ll> que;
que.push(i);
gr2[i]=c2;
while(!que.empty()){
ll t=que.front();que.pop();
rep(j,n)if(v[j][t]==1&&gr2[j]==-1){
gr2[j]=c2;que.push(j);
}
}
c2++;
}
vector<vector<int>> ans(n,vector<int>(n));
vvi al2(c2);
rep(i,n)al2[gr2[i]].pb(i);
rep(i,c2)rep(j,al2[i].size()-1){
ll a=al2[i][j],b=al2[i][j+1];
ans[a][b]=ans[b][a]=1;
}
rep(i,c1)if(al1[i].size()>1){
if(al1[i].size()==2)return 0;
rep(j,al1[i].size()){
ll a=al1[i][j],b=al1[i][(j+1)%al1[i].size()];
ans[a][b]=ans[b][a]=1;
}
}
rep(i,n)rep(j,i)if(v[i][j]==2&&gr2[i]==gr2[j])return 0;
rep(i,n)rep(j,i)if(v[i][j]==1&&gr2[i]!=gr2[j])return 0;
build(ans);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
8 ms |
1160 KB |
Output is correct |
7 |
Correct |
179 ms |
21984 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 |
8 ms |
1160 KB |
Output is correct |
7 |
Correct |
179 ms |
21984 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 |
8 ms |
1152 KB |
Output is correct |
13 |
Correct |
186 ms |
22136 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
596 KB |
Output is correct |
17 |
Correct |
77 ms |
8080 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
46 ms |
5676 KB |
Output is correct |
21 |
Correct |
200 ms |
22004 KB |
Output is correct |
22 |
Correct |
217 ms |
22020 KB |
Output is correct |
23 |
Correct |
176 ms |
22016 KB |
Output is correct |
24 |
Correct |
168 ms |
22084 KB |
Output is correct |
25 |
Correct |
67 ms |
8140 KB |
Output is correct |
26 |
Correct |
78 ms |
8080 KB |
Output is correct |
27 |
Correct |
176 ms |
22020 KB |
Output is correct |
28 |
Correct |
170 ms |
22116 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 |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
7 ms |
1108 KB |
Output is correct |
9 |
Correct |
172 ms |
22064 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1108 KB |
Output is correct |
13 |
Correct |
164 ms |
22116 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
102 ms |
8084 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
48 ms |
5792 KB |
Output is correct |
22 |
Correct |
193 ms |
22024 KB |
Output is correct |
23 |
Correct |
193 ms |
22032 KB |
Output is correct |
24 |
Correct |
197 ms |
22108 KB |
Output is correct |
25 |
Correct |
75 ms |
12236 KB |
Output is correct |
26 |
Correct |
66 ms |
8140 KB |
Output is correct |
27 |
Correct |
169 ms |
22020 KB |
Output is correct |
28 |
Correct |
188 ms |
22120 KB |
Output is correct |
29 |
Correct |
71 ms |
12204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
52 ms |
5732 KB |
Output is correct |
5 |
Correct |
226 ms |
21968 KB |
Output is correct |
6 |
Correct |
174 ms |
22148 KB |
Output is correct |
7 |
Correct |
220 ms |
22032 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
51 ms |
5732 KB |
Output is correct |
10 |
Correct |
193 ms |
22056 KB |
Output is correct |
11 |
Correct |
200 ms |
22084 KB |
Output is correct |
12 |
Correct |
190 ms |
22116 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
42 ms |
5708 KB |
Output is correct |
17 |
Correct |
172 ms |
22020 KB |
Output is correct |
18 |
Correct |
176 ms |
22092 KB |
Output is correct |
19 |
Correct |
171 ms |
22092 KB |
Output is correct |
20 |
Correct |
170 ms |
22132 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 |
8 ms |
1160 KB |
Output is correct |
7 |
Correct |
179 ms |
21984 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 |
8 ms |
1152 KB |
Output is correct |
13 |
Correct |
186 ms |
22136 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
596 KB |
Output is correct |
17 |
Correct |
77 ms |
8080 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
46 ms |
5676 KB |
Output is correct |
21 |
Correct |
200 ms |
22004 KB |
Output is correct |
22 |
Correct |
217 ms |
22020 KB |
Output is correct |
23 |
Correct |
176 ms |
22016 KB |
Output is correct |
24 |
Correct |
168 ms |
22084 KB |
Output is correct |
25 |
Correct |
67 ms |
8140 KB |
Output is correct |
26 |
Correct |
78 ms |
8080 KB |
Output is correct |
27 |
Correct |
176 ms |
22020 KB |
Output is correct |
28 |
Correct |
170 ms |
22116 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1108 KB |
Output is correct |
37 |
Correct |
172 ms |
22064 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1108 KB |
Output is correct |
41 |
Correct |
164 ms |
22116 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
596 KB |
Output is correct |
45 |
Correct |
102 ms |
8084 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
48 ms |
5792 KB |
Output is correct |
50 |
Correct |
193 ms |
22024 KB |
Output is correct |
51 |
Correct |
193 ms |
22032 KB |
Output is correct |
52 |
Correct |
197 ms |
22108 KB |
Output is correct |
53 |
Correct |
75 ms |
12236 KB |
Output is correct |
54 |
Correct |
66 ms |
8140 KB |
Output is correct |
55 |
Correct |
169 ms |
22020 KB |
Output is correct |
56 |
Correct |
188 ms |
22120 KB |
Output is correct |
57 |
Correct |
71 ms |
12204 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
3 ms |
596 KB |
Output is correct |
61 |
Correct |
74 ms |
8188 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 |
300 KB |
Output is correct |
65 |
Correct |
41 ms |
6220 KB |
Output is correct |
66 |
Correct |
78 ms |
10104 KB |
Output is correct |
67 |
Correct |
77 ms |
10112 KB |
Output is correct |
68 |
Correct |
67 ms |
10060 KB |
Output is correct |
69 |
Correct |
73 ms |
14212 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 |
8 ms |
1160 KB |
Output is correct |
7 |
Correct |
179 ms |
21984 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 |
8 ms |
1152 KB |
Output is correct |
13 |
Correct |
186 ms |
22136 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
596 KB |
Output is correct |
17 |
Correct |
77 ms |
8080 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
46 ms |
5676 KB |
Output is correct |
21 |
Correct |
200 ms |
22004 KB |
Output is correct |
22 |
Correct |
217 ms |
22020 KB |
Output is correct |
23 |
Correct |
176 ms |
22016 KB |
Output is correct |
24 |
Correct |
168 ms |
22084 KB |
Output is correct |
25 |
Correct |
67 ms |
8140 KB |
Output is correct |
26 |
Correct |
78 ms |
8080 KB |
Output is correct |
27 |
Correct |
176 ms |
22020 KB |
Output is correct |
28 |
Correct |
170 ms |
22116 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1108 KB |
Output is correct |
37 |
Correct |
172 ms |
22064 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1108 KB |
Output is correct |
41 |
Correct |
164 ms |
22116 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
596 KB |
Output is correct |
45 |
Correct |
102 ms |
8084 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
48 ms |
5792 KB |
Output is correct |
50 |
Correct |
193 ms |
22024 KB |
Output is correct |
51 |
Correct |
193 ms |
22032 KB |
Output is correct |
52 |
Correct |
197 ms |
22108 KB |
Output is correct |
53 |
Correct |
75 ms |
12236 KB |
Output is correct |
54 |
Correct |
66 ms |
8140 KB |
Output is correct |
55 |
Correct |
169 ms |
22020 KB |
Output is correct |
56 |
Correct |
188 ms |
22120 KB |
Output is correct |
57 |
Correct |
71 ms |
12204 KB |
Output is correct |
58 |
Correct |
1 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 |
52 ms |
5732 KB |
Output is correct |
62 |
Correct |
226 ms |
21968 KB |
Output is correct |
63 |
Correct |
174 ms |
22148 KB |
Output is correct |
64 |
Correct |
220 ms |
22032 KB |
Output is correct |
65 |
Correct |
1 ms |
332 KB |
Output is correct |
66 |
Correct |
51 ms |
5732 KB |
Output is correct |
67 |
Correct |
193 ms |
22056 KB |
Output is correct |
68 |
Correct |
200 ms |
22084 KB |
Output is correct |
69 |
Correct |
190 ms |
22116 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
42 ms |
5708 KB |
Output is correct |
74 |
Correct |
172 ms |
22020 KB |
Output is correct |
75 |
Correct |
176 ms |
22092 KB |
Output is correct |
76 |
Correct |
171 ms |
22092 KB |
Output is correct |
77 |
Correct |
170 ms |
22132 KB |
Output is correct |
78 |
Correct |
0 ms |
212 KB |
Output is correct |
79 |
Correct |
0 ms |
212 KB |
Output is correct |
80 |
Correct |
3 ms |
596 KB |
Output is correct |
81 |
Correct |
74 ms |
8188 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 |
300 KB |
Output is correct |
85 |
Correct |
41 ms |
6220 KB |
Output is correct |
86 |
Correct |
78 ms |
10104 KB |
Output is correct |
87 |
Correct |
77 ms |
10112 KB |
Output is correct |
88 |
Correct |
67 ms |
10060 KB |
Output is correct |
89 |
Correct |
73 ms |
14212 KB |
Output is correct |
90 |
Correct |
1 ms |
212 KB |
Output is correct |
91 |
Correct |
1 ms |
212 KB |
Output is correct |
92 |
Correct |
3 ms |
596 KB |
Output is correct |
93 |
Correct |
75 ms |
10104 KB |
Output is correct |
94 |
Correct |
1 ms |
304 KB |
Output is correct |
95 |
Correct |
1 ms |
212 KB |
Output is correct |
96 |
Correct |
1 ms |
212 KB |
Output is correct |
97 |
Correct |
18 ms |
2692 KB |
Output is correct |
98 |
Correct |
65 ms |
10100 KB |
Output is correct |
99 |
Correct |
71 ms |
10108 KB |
Output is correct |
100 |
Correct |
62 ms |
10104 KB |
Output is correct |
101 |
Correct |
62 ms |
10104 KB |
Output is correct |
102 |
Correct |
72 ms |
10104 KB |
Output is correct |
103 |
Correct |
73 ms |
10104 KB |
Output is correct |
104 |
Correct |
60 ms |
10108 KB |
Output is correct |
105 |
Correct |
77 ms |
10032 KB |
Output is correct |