Submission #301697

# Submission time Handle Problem Language Result Execution time Memory
301697 2020-09-18T06:17:34 Z tinjyu Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
290 ms 26276 KB
#include "supertrees.h"
#include <vector>
#include <iostream>
using namespace std;
int f[100005],map[1005][1005],pre[10005],tmp[10005],circle[100005],ccnt,tag[10005],tmp2[100005],tag2[100005];
int find(int x)
{
if(f[x]==x)return x;
else return f[x]=find(f[x]);
}
int construct(std::vector<std::vector<int>> p) {

int n = p[0].size();
std::vector<std::vector<int>> answer;
for(int i=0;i<n;i++)f[i]=i;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(p[i][j]==3)return 0;
if(i==j)continue;
int fx=find(i),fy=find(j);
if(p[i][j]==0 && fx==fy)return 0;

if(p[i][j]!=0)
{
f[fx]=fy;
}
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
int fx=find(i),fy=find(j);
if(p[i][j]==0 && fx==fy)return 0;
}
}
for(int i=0;i<n;i++)
{
pre[i]=-1;
}
for(int i=0;i<n;i++)
{
int cnt=0;
for(int j=0;j<n;j++)
{
if(find(j)==i)
{
cnt++;
tmp[cnt]=j;
}
}
if(cnt==0)continue;
//cout<<i<<endl;
//for(int j=1;j<=cnt;j++)cout<<tmp[j]<<" ";
//cout<<endl;
ccnt=0;
for(int j=0;j<n;j++)tag2[j]=0;
for(int j=1;j<=cnt;j++)//in one set
{
if(tag[tmp[j]]==1)continue;
int x=tmp[j],cnt2=0;
tag[x]=1;
tmp2[0]=x;
tag2[x]=x;
for(int k=1;k<=cnt;k++)
{
int y=tmp[k];
if(x==y)continue;
if(p[x][y]==1)
{
cnt2++;
tmp2[cnt2]=y;
tag2[y]=x;
tag[y]=1;
}
}
for(int k=1;k<=cnt2;k++)
{
int y=tmp2[k];
//cout<<y<<endl;
int count=0;
for(int l=1;l<=cnt;l++)
{
int z=tmp[l];
if(y==z)continue;
if(p[y][z]==1)
{
//cout<<z<<" ";
if(tag2[z]!=x)return 0;
count++;
}
}
//cout<<count<<endl;
if(count!=cnt2)return 0;
}
for(int k=0;k<cnt2;k++)
{
map[tmp2[k]][tmp2[k+1]]=1;
map[tmp2[k+1]][tmp2[k]]=1;
}
ccnt++;
//cout<<ccnt<<endl;
circle[ccnt]=x;
}
if(ccnt==1)continue;
if(ccnt==2)return 0;
for(int i=1;i<ccnt;i++)
{
map[circle[i]][circle[i+1]]=1;
map[circle[i+1]][circle[i]]=1;
}
map[circle[1]][circle[ccnt]]=1;
map[circle[ccnt]][circle[1]]=1;
}
for(int i=0;i<n;i++)
{
vector<int> tmp(n);
for(int j=0;j<n;j++)tmp[j]=map[i][j];
answer.push_back(tmp);
}
build(answer);
return 1;
}
# Verdict Execution time Memory 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 15 ms 2048 KB Output is correct
7 Correct 268 ms 26204 KB Output is correct
# Verdict Execution time Memory 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 15 ms 2048 KB Output is correct
7 Correct 268 ms 26204 KB Output is correct
8 Correct 1 ms 416 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 14 ms 1280 KB Output is correct
13 Correct 259 ms 22136 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 111 ms 8292 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 67 ms 7672 KB Output is correct
21 Correct 258 ms 26104 KB Output is correct
22 Correct 264 ms 25852 KB Output is correct
23 Correct 285 ms 26108 KB Output is correct
24 Correct 249 ms 22552 KB Output is correct
25 Correct 108 ms 8188 KB Output is correct
26 Correct 102 ms 8156 KB Output is correct
27 Correct 284 ms 26276 KB Output is correct
28 Correct 252 ms 22520 KB Output is correct
# Verdict Execution time Memory 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 512 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 12 ms 1280 KB Output is correct
9 Correct 247 ms 22136 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 12 ms 2048 KB Output is correct
13 Correct 271 ms 26104 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 110 ms 8184 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 65 ms 7672 KB Output is correct
22 Correct 257 ms 26104 KB Output is correct
23 Correct 259 ms 26104 KB Output is correct
24 Correct 287 ms 26104 KB Output is correct
25 Correct 106 ms 8440 KB Output is correct
26 Correct 102 ms 8184 KB Output is correct
27 Correct 265 ms 26104 KB Output is correct
28 Correct 288 ms 26184 KB Output is correct
29 Correct 106 ms 8440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 66 ms 7672 KB Output is correct
5 Correct 261 ms 26104 KB Output is correct
6 Correct 260 ms 25720 KB Output is correct
7 Correct 290 ms 26104 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 65 ms 7672 KB Output is correct
10 Correct 265 ms 26204 KB Output is correct
11 Correct 264 ms 25976 KB Output is correct
12 Correct 281 ms 26104 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 384 KB Output is correct
16 Correct 66 ms 7676 KB Output is correct
17 Correct 266 ms 26104 KB Output is correct
18 Correct 257 ms 25976 KB Output is correct
19 Correct 257 ms 26104 KB Output is correct
20 Correct 241 ms 22392 KB Output is correct
# Verdict Execution time Memory 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 15 ms 2048 KB Output is correct
7 Correct 268 ms 26204 KB Output is correct
8 Correct 1 ms 416 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 14 ms 1280 KB Output is correct
13 Correct 259 ms 22136 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 111 ms 8292 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 67 ms 7672 KB Output is correct
21 Correct 258 ms 26104 KB Output is correct
22 Correct 264 ms 25852 KB Output is correct
23 Correct 285 ms 26108 KB Output is correct
24 Correct 249 ms 22552 KB Output is correct
25 Correct 108 ms 8188 KB Output is correct
26 Correct 102 ms 8156 KB Output is correct
27 Correct 284 ms 26276 KB Output is correct
28 Correct 252 ms 22520 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 512 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 12 ms 1280 KB Output is correct
37 Correct 247 ms 22136 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 12 ms 2048 KB Output is correct
41 Correct 271 ms 26104 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 5 ms 640 KB Output is correct
45 Correct 110 ms 8184 KB Output is correct
46 Correct 1 ms 256 KB Output is correct
47 Correct 1 ms 256 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 65 ms 7672 KB Output is correct
50 Correct 257 ms 26104 KB Output is correct
51 Correct 259 ms 26104 KB Output is correct
52 Correct 287 ms 26104 KB Output is correct
53 Correct 106 ms 8440 KB Output is correct
54 Correct 102 ms 8184 KB Output is correct
55 Correct 265 ms 26104 KB Output is correct
56 Correct 288 ms 26184 KB Output is correct
57 Correct 106 ms 8440 KB Output is correct
58 Correct 0 ms 256 KB Output is correct
59 Correct 1 ms 288 KB Output is correct
60 Correct 5 ms 640 KB Output is correct
61 Correct 119 ms 8188 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 64 ms 7672 KB Output is correct
66 Correct 102 ms 8184 KB Output is correct
67 Correct 99 ms 8184 KB Output is correct
68 Correct 100 ms 8184 KB Output is correct
69 Correct 109 ms 8184 KB Output is correct
# Verdict Execution time Memory 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 15 ms 2048 KB Output is correct
7 Correct 268 ms 26204 KB Output is correct
8 Correct 1 ms 416 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 14 ms 1280 KB Output is correct
13 Correct 259 ms 22136 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 111 ms 8292 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 67 ms 7672 KB Output is correct
21 Correct 258 ms 26104 KB Output is correct
22 Correct 264 ms 25852 KB Output is correct
23 Correct 285 ms 26108 KB Output is correct
24 Correct 249 ms 22552 KB Output is correct
25 Correct 108 ms 8188 KB Output is correct
26 Correct 102 ms 8156 KB Output is correct
27 Correct 284 ms 26276 KB Output is correct
28 Correct 252 ms 22520 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 512 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 12 ms 1280 KB Output is correct
37 Correct 247 ms 22136 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 12 ms 2048 KB Output is correct
41 Correct 271 ms 26104 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 5 ms 640 KB Output is correct
45 Correct 110 ms 8184 KB Output is correct
46 Correct 1 ms 256 KB Output is correct
47 Correct 1 ms 256 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 65 ms 7672 KB Output is correct
50 Correct 257 ms 26104 KB Output is correct
51 Correct 259 ms 26104 KB Output is correct
52 Correct 287 ms 26104 KB Output is correct
53 Correct 106 ms 8440 KB Output is correct
54 Correct 102 ms 8184 KB Output is correct
55 Correct 265 ms 26104 KB Output is correct
56 Correct 288 ms 26184 KB Output is correct
57 Correct 106 ms 8440 KB Output is correct
58 Correct 1 ms 512 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 66 ms 7672 KB Output is correct
62 Correct 261 ms 26104 KB Output is correct
63 Correct 260 ms 25720 KB Output is correct
64 Correct 290 ms 26104 KB Output is correct
65 Correct 1 ms 512 KB Output is correct
66 Correct 65 ms 7672 KB Output is correct
67 Correct 265 ms 26204 KB Output is correct
68 Correct 264 ms 25976 KB Output is correct
69 Correct 281 ms 26104 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 384 KB Output is correct
73 Correct 66 ms 7676 KB Output is correct
74 Correct 266 ms 26104 KB Output is correct
75 Correct 257 ms 25976 KB Output is correct
76 Correct 257 ms 26104 KB Output is correct
77 Correct 241 ms 22392 KB Output is correct
78 Correct 0 ms 256 KB Output is correct
79 Correct 1 ms 288 KB Output is correct
80 Correct 5 ms 640 KB Output is correct
81 Correct 119 ms 8188 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 64 ms 7672 KB Output is correct
86 Correct 102 ms 8184 KB Output is correct
87 Correct 99 ms 8184 KB Output is correct
88 Correct 100 ms 8184 KB Output is correct
89 Correct 109 ms 8184 KB Output is correct
90 Correct 1 ms 256 KB Output is correct
91 Correct 1 ms 256 KB Output is correct
92 Correct 5 ms 640 KB Output is correct
93 Correct 111 ms 8184 KB Output is correct
94 Correct 1 ms 256 KB Output is correct
95 Correct 1 ms 256 KB Output is correct
96 Correct 1 ms 256 KB Output is correct
97 Correct 25 ms 2304 KB Output is correct
98 Correct 100 ms 8184 KB Output is correct
99 Correct 103 ms 8184 KB Output is correct
100 Correct 100 ms 8156 KB Output is correct
101 Correct 101 ms 8184 KB Output is correct
102 Correct 110 ms 8188 KB Output is correct
103 Correct 115 ms 8156 KB Output is correct
104 Correct 112 ms 8184 KB Output is correct
105 Correct 113 ms 8216 KB Output is correct