#include<bits/stdc++.h>
using namespace std;
#include "supertrees.h"
#include <vector>
int d[1005][1005],p1[1005],p2[1005],type,u,ans[1005][1005],vis[1005],cnt;
vector<int> v[1005],g[1005],kawin;
set<int> s[1005];
queue<int> q;
int f1(int a)
{
if(p1[a]==a)
{
return a;
}
return p1[a]=f1(p1[a]);
}
void un1(int b,int c)
{
p1[f1(b)]=f1(c);
}
int f2(int a)
{
if(p2[a]==a)
{
return a;
}
return p2[a]=f2(p2[a]);
}
void un2(int b,int c)
{
p2[f2(b)]=f2(c);
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> answer;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
d[i][j]=p[i-1][j-1];
}
p1[i]=i;
p2[i]=i;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(d[i][j]>=1)
{
un1(i,j);
}
if(d[i][j]==1)
{
un2(i,j);
}
}
}
/*for(int i=1;i<=n;i++)
{
printf("%d %d\n",p1[i],p2[i]);
}*/
type=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(f1(i)!=f1(j))
{
if(d[i][j]!=0)
{
type=-1;
}
}else
{
if(f2(i)==f2(j))
{
if(d[i][j]!=1)
{
type=-1;
}
}else
{
if(d[i][j]!=2)
{
type=-1;
}
}
}
}
}
memset(vis,-1,sizeof vis);
for(int i=1;i<=n;i++)
{
if(vis[i]==-1)
{
cnt=0;
q.push(i);
vis[i]=0;
while(!q.empty())
{
u=q.front();
++cnt;
q.pop();
for(int i=1;i<=n;i++)
{
if(d[u][i]==2)
{
if(vis[i]==-1)
{
vis[i]=0;
q.push(i);
}
}
}
}
if(cnt==2)
{
type=-1;
}
}
}
//printf("%d\n",type);
for(int i=1;i<=n;i++)
{
v[f2(i)].push_back(i);
s[f1(i)].insert(f2(i));
//g[f1(i)].push_back(f2(i));
//printf("%d %d\n",f1(i),f2(i));
}
/*printf("9holo\n");
for(auto it=s[4].begin();it!=s[4].end();it++)
{
printf("%d ",*it);
}
printf("\n");*/
for(int i=1;i<=n;i++)
{
//printf("atittarn=%d\n",i);
for(auto it=s[i].begin();it!=s[i].end();it++)
{
//printf("%d ",*it);
g[i].push_back(*it);
}
//printf("\n");
/*for(int j=0;j<g[i].size();j++)
{
printf("%d ",g[i][j]);
}
printf("\n");*/
}
for(int i=1;i<=n;i++)
{
u=i;
//printf("%d\n",i);
for(int j=0;j<(int)v[i].size();j++)
{
//printf("%d ",v[i][j]);
if(v[i][j]!=i)
{
ans[u][v[i][j]]=1;
ans[v[i][j]][u]=1;
u=v[i][j];
}
}
//printf("\n");
if(g[i].size()>=2)
{
for(int j=0;j<(int)g[i].size()-1;j++)
{
ans[g[i][j]][g[i][j+1]]=1;
ans[g[i][j+1]][g[i][j]]=1;
}
ans[g[i][0]][g[i][g[i].size()-1]]=1;
ans[g[i][g[i].size()-1]][g[i][0]]=1;
}
}
/*for(int i=1;i<=n;i++)
{
ans[i][i]=1;
}*/
for(int i=1;i<=n;i++)
{
kawin.clear();
for(int j=1;j<=n;j++)
{
kawin.push_back(ans[i][j]);
}
answer.push_back(kawin);
}
if(type==-1)
{
return 0;
}
build(answer);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
408 KB |
Output is correct |
6 |
Correct |
8 ms |
2764 KB |
Output is correct |
7 |
Correct |
182 ms |
29964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
408 KB |
Output is correct |
6 |
Correct |
8 ms |
2764 KB |
Output is correct |
7 |
Correct |
182 ms |
29964 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
7 ms |
1996 KB |
Output is correct |
13 |
Correct |
193 ms |
26276 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
5 ms |
2380 KB |
Output is correct |
17 |
Correct |
96 ms |
20080 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
44 ms |
9564 KB |
Output is correct |
21 |
Correct |
221 ms |
30004 KB |
Output is correct |
22 |
Correct |
173 ms |
29600 KB |
Output is correct |
23 |
Correct |
194 ms |
30044 KB |
Output is correct |
24 |
Correct |
194 ms |
26336 KB |
Output is correct |
25 |
Correct |
88 ms |
20080 KB |
Output is correct |
26 |
Correct |
78 ms |
19696 KB |
Output is correct |
27 |
Correct |
183 ms |
30048 KB |
Output is correct |
28 |
Correct |
186 ms |
26340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
392 KB |
Output is correct |
6 |
Correct |
0 ms |
396 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
8 ms |
2180 KB |
Output is correct |
9 |
Correct |
171 ms |
28100 KB |
Output is correct |
10 |
Correct |
1 ms |
392 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
9 ms |
2968 KB |
Output is correct |
13 |
Correct |
209 ms |
32028 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
388 KB |
Output is correct |
16 |
Correct |
5 ms |
2508 KB |
Output is correct |
17 |
Correct |
99 ms |
22148 KB |
Output is correct |
18 |
Correct |
1 ms |
388 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
43 ms |
10180 KB |
Output is correct |
22 |
Correct |
190 ms |
31976 KB |
Output is correct |
23 |
Correct |
169 ms |
31956 KB |
Output is correct |
24 |
Correct |
193 ms |
32060 KB |
Output is correct |
25 |
Correct |
74 ms |
18392 KB |
Output is correct |
26 |
Correct |
88 ms |
22100 KB |
Output is correct |
27 |
Correct |
178 ms |
31968 KB |
Output is correct |
28 |
Correct |
182 ms |
31972 KB |
Output is correct |
29 |
Correct |
87 ms |
18396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
44 ms |
9540 KB |
Output is correct |
5 |
Correct |
170 ms |
30020 KB |
Output is correct |
6 |
Correct |
170 ms |
29500 KB |
Output is correct |
7 |
Correct |
184 ms |
29920 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
45 ms |
9692 KB |
Output is correct |
10 |
Correct |
172 ms |
30068 KB |
Output is correct |
11 |
Correct |
168 ms |
29976 KB |
Output is correct |
12 |
Correct |
181 ms |
30064 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
43 ms |
9656 KB |
Output is correct |
17 |
Correct |
175 ms |
30048 KB |
Output is correct |
18 |
Correct |
174 ms |
29892 KB |
Output is correct |
19 |
Correct |
172 ms |
30060 KB |
Output is correct |
20 |
Correct |
164 ms |
26352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
408 KB |
Output is correct |
6 |
Correct |
8 ms |
2764 KB |
Output is correct |
7 |
Correct |
182 ms |
29964 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
7 ms |
1996 KB |
Output is correct |
13 |
Correct |
193 ms |
26276 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
5 ms |
2380 KB |
Output is correct |
17 |
Correct |
96 ms |
20080 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
44 ms |
9564 KB |
Output is correct |
21 |
Correct |
221 ms |
30004 KB |
Output is correct |
22 |
Correct |
173 ms |
29600 KB |
Output is correct |
23 |
Correct |
194 ms |
30044 KB |
Output is correct |
24 |
Correct |
194 ms |
26336 KB |
Output is correct |
25 |
Correct |
88 ms |
20080 KB |
Output is correct |
26 |
Correct |
78 ms |
19696 KB |
Output is correct |
27 |
Correct |
183 ms |
30048 KB |
Output is correct |
28 |
Correct |
186 ms |
26340 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
0 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
392 KB |
Output is correct |
34 |
Correct |
0 ms |
396 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
8 ms |
2180 KB |
Output is correct |
37 |
Correct |
171 ms |
28100 KB |
Output is correct |
38 |
Correct |
1 ms |
392 KB |
Output is correct |
39 |
Correct |
1 ms |
460 KB |
Output is correct |
40 |
Correct |
9 ms |
2968 KB |
Output is correct |
41 |
Correct |
209 ms |
32028 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
388 KB |
Output is correct |
44 |
Correct |
5 ms |
2508 KB |
Output is correct |
45 |
Correct |
99 ms |
22148 KB |
Output is correct |
46 |
Correct |
1 ms |
388 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
43 ms |
10180 KB |
Output is correct |
50 |
Correct |
190 ms |
31976 KB |
Output is correct |
51 |
Correct |
169 ms |
31956 KB |
Output is correct |
52 |
Correct |
193 ms |
32060 KB |
Output is correct |
53 |
Correct |
74 ms |
18392 KB |
Output is correct |
54 |
Correct |
88 ms |
22100 KB |
Output is correct |
55 |
Correct |
178 ms |
31968 KB |
Output is correct |
56 |
Correct |
182 ms |
31972 KB |
Output is correct |
57 |
Correct |
87 ms |
18396 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
1 ms |
460 KB |
Output is correct |
60 |
Correct |
5 ms |
2508 KB |
Output is correct |
61 |
Correct |
102 ms |
22000 KB |
Output is correct |
62 |
Correct |
0 ms |
332 KB |
Output is correct |
63 |
Correct |
1 ms |
460 KB |
Output is correct |
64 |
Correct |
1 ms |
460 KB |
Output is correct |
65 |
Correct |
45 ms |
10192 KB |
Output is correct |
66 |
Correct |
82 ms |
22084 KB |
Output is correct |
67 |
Correct |
81 ms |
21984 KB |
Output is correct |
68 |
Correct |
80 ms |
21972 KB |
Output is correct |
69 |
Correct |
78 ms |
18516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
408 KB |
Output is correct |
6 |
Correct |
8 ms |
2764 KB |
Output is correct |
7 |
Correct |
182 ms |
29964 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
7 ms |
1996 KB |
Output is correct |
13 |
Correct |
193 ms |
26276 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
5 ms |
2380 KB |
Output is correct |
17 |
Correct |
96 ms |
20080 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
44 ms |
9564 KB |
Output is correct |
21 |
Correct |
221 ms |
30004 KB |
Output is correct |
22 |
Correct |
173 ms |
29600 KB |
Output is correct |
23 |
Correct |
194 ms |
30044 KB |
Output is correct |
24 |
Correct |
194 ms |
26336 KB |
Output is correct |
25 |
Correct |
88 ms |
20080 KB |
Output is correct |
26 |
Correct |
78 ms |
19696 KB |
Output is correct |
27 |
Correct |
183 ms |
30048 KB |
Output is correct |
28 |
Correct |
186 ms |
26340 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
0 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
392 KB |
Output is correct |
34 |
Correct |
0 ms |
396 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
8 ms |
2180 KB |
Output is correct |
37 |
Correct |
171 ms |
28100 KB |
Output is correct |
38 |
Correct |
1 ms |
392 KB |
Output is correct |
39 |
Correct |
1 ms |
460 KB |
Output is correct |
40 |
Correct |
9 ms |
2968 KB |
Output is correct |
41 |
Correct |
209 ms |
32028 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
388 KB |
Output is correct |
44 |
Correct |
5 ms |
2508 KB |
Output is correct |
45 |
Correct |
99 ms |
22148 KB |
Output is correct |
46 |
Correct |
1 ms |
388 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
43 ms |
10180 KB |
Output is correct |
50 |
Correct |
190 ms |
31976 KB |
Output is correct |
51 |
Correct |
169 ms |
31956 KB |
Output is correct |
52 |
Correct |
193 ms |
32060 KB |
Output is correct |
53 |
Correct |
74 ms |
18392 KB |
Output is correct |
54 |
Correct |
88 ms |
22100 KB |
Output is correct |
55 |
Correct |
178 ms |
31968 KB |
Output is correct |
56 |
Correct |
182 ms |
31972 KB |
Output is correct |
57 |
Correct |
87 ms |
18396 KB |
Output is correct |
58 |
Correct |
0 ms |
332 KB |
Output is correct |
59 |
Correct |
1 ms |
332 KB |
Output is correct |
60 |
Correct |
1 ms |
332 KB |
Output is correct |
61 |
Correct |
44 ms |
9540 KB |
Output is correct |
62 |
Correct |
170 ms |
30020 KB |
Output is correct |
63 |
Correct |
170 ms |
29500 KB |
Output is correct |
64 |
Correct |
184 ms |
29920 KB |
Output is correct |
65 |
Correct |
1 ms |
332 KB |
Output is correct |
66 |
Correct |
45 ms |
9692 KB |
Output is correct |
67 |
Correct |
172 ms |
30068 KB |
Output is correct |
68 |
Correct |
168 ms |
29976 KB |
Output is correct |
69 |
Correct |
181 ms |
30064 KB |
Output is correct |
70 |
Correct |
1 ms |
332 KB |
Output is correct |
71 |
Correct |
1 ms |
460 KB |
Output is correct |
72 |
Correct |
1 ms |
460 KB |
Output is correct |
73 |
Correct |
43 ms |
9656 KB |
Output is correct |
74 |
Correct |
175 ms |
30048 KB |
Output is correct |
75 |
Correct |
174 ms |
29892 KB |
Output is correct |
76 |
Correct |
172 ms |
30060 KB |
Output is correct |
77 |
Correct |
164 ms |
26352 KB |
Output is correct |
78 |
Correct |
1 ms |
332 KB |
Output is correct |
79 |
Correct |
1 ms |
460 KB |
Output is correct |
80 |
Correct |
5 ms |
2508 KB |
Output is correct |
81 |
Correct |
102 ms |
22000 KB |
Output is correct |
82 |
Correct |
0 ms |
332 KB |
Output is correct |
83 |
Correct |
1 ms |
460 KB |
Output is correct |
84 |
Correct |
1 ms |
460 KB |
Output is correct |
85 |
Correct |
45 ms |
10192 KB |
Output is correct |
86 |
Correct |
82 ms |
22084 KB |
Output is correct |
87 |
Correct |
81 ms |
21984 KB |
Output is correct |
88 |
Correct |
80 ms |
21972 KB |
Output is correct |
89 |
Correct |
78 ms |
18516 KB |
Output is correct |
90 |
Correct |
1 ms |
388 KB |
Output is correct |
91 |
Correct |
1 ms |
460 KB |
Output is correct |
92 |
Correct |
5 ms |
2508 KB |
Output is correct |
93 |
Correct |
106 ms |
21980 KB |
Output is correct |
94 |
Correct |
0 ms |
332 KB |
Output is correct |
95 |
Correct |
1 ms |
460 KB |
Output is correct |
96 |
Correct |
1 ms |
460 KB |
Output is correct |
97 |
Correct |
21 ms |
7636 KB |
Output is correct |
98 |
Correct |
81 ms |
22120 KB |
Output is correct |
99 |
Correct |
94 ms |
21860 KB |
Output is correct |
100 |
Correct |
78 ms |
21956 KB |
Output is correct |
101 |
Correct |
73 ms |
18404 KB |
Output is correct |
102 |
Correct |
82 ms |
22112 KB |
Output is correct |
103 |
Correct |
94 ms |
22140 KB |
Output is correct |
104 |
Correct |
95 ms |
22116 KB |
Output is correct |
105 |
Correct |
90 ms |
22108 KB |
Output is correct |