Submission #750865

# Submission time Handle Problem Language Result Execution time Memory
750865 2023-05-30T11:56:27 Z bachhoangxuan Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
184 ms 24140 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

int construct(std::vector<std::vector<int>> p) {
	int n = (int)p.size();
	std::vector<std::vector<int>> b(n,vector<int>(n,0));
    vector<int> vis0(n,0),vis1(n,0),v0,v1;
    function<void(int)> dfs0 = [&](int u){
        vis0[u]=1;v0.push_back(u);
        for(int i=0;i<n;i++){
            if(p[u][i]==0 || vis0[i]) continue;
            dfs0(i);
        }
    };
    function<void(int)> dfs1 = [&](int u){
        vis1[u]=1;v1.push_back(u);
        for(int i=0;i<n;i++){
            if(p[u][i]!=1 || vis1[i]) continue;
            dfs1(i);
        }
    };
    for(int i=0;i<n;i++){
        if(!vis0[i]){
            v0.clear();dfs0(i);
            for(int x:v0){
                for(int y:v0) if(p[x][y]!=1 && p[x][y]!=2) return 0;
            }
            vector<int> pre,cycle;
            for(int u:v0){
                if(!vis1[u]){
                    v1.clear();dfs1(u);
                    for(int x:v1){
                        for(int y:v1) if(p[x][y]!=1) return 0;
                    }
                    for(int j=1;j<(int)v1.size();j++){
                        int x=v1[j-1],y=v1[j];
                        b[x][y]=b[y][x]=1;
                    }
                    for(int x:v1){
                        for(int y:pre) if(p[x][y]!=2) return 0;
                    }
                    for(int x:v1) pre.push_back(x);
                    cycle.push_back(v1[0]);
                }
            }
            int sz=(int)cycle.size();
            if(sz==2) return 0;
            else if(sz>2){
                for(int j=0;j<sz;j++) b[cycle[j]][cycle[(j+1)%sz]]=b[cycle[(j+1)%sz]][cycle[j]]=1;
            }
        }
    }
	build(b);
	return 1;
}
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
6 Correct 7 ms 1280 KB Output is correct
7 Correct 166 ms 24056 KB Output is correct
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
6 Correct 7 ms 1280 KB Output is correct
7 Correct 166 ms 24056 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 180 ms 24016 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 80 ms 14076 KB Output is correct
18 Correct 0 ms 296 KB Output is correct
19 Correct 0 ms 296 KB Output is correct
20 Correct 42 ms 6220 KB Output is correct
21 Correct 166 ms 23928 KB Output is correct
22 Correct 167 ms 24012 KB Output is correct
23 Correct 173 ms 23928 KB Output is correct
24 Correct 166 ms 23944 KB Output is correct
25 Correct 71 ms 14068 KB Output is correct
26 Correct 69 ms 14204 KB Output is correct
27 Correct 172 ms 23924 KB Output is correct
28 Correct 167 ms 23924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 8 ms 1232 KB Output is correct
9 Correct 169 ms 24012 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 1176 KB Output is correct
13 Correct 171 ms 23956 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 828 KB Output is correct
17 Correct 81 ms 14084 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 42 ms 6220 KB Output is correct
22 Correct 168 ms 24140 KB Output is correct
23 Correct 166 ms 23924 KB Output is correct
24 Correct 177 ms 24012 KB Output is correct
25 Correct 66 ms 14100 KB Output is correct
26 Correct 66 ms 14068 KB Output is correct
27 Correct 177 ms 23940 KB Output is correct
28 Correct 179 ms 23928 KB Output is correct
29 Correct 89 ms 14076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 46 ms 6168 KB Output is correct
5 Correct 184 ms 23908 KB Output is correct
6 Correct 174 ms 23944 KB Output is correct
7 Correct 180 ms 23988 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 45 ms 6264 KB Output is correct
10 Correct 168 ms 23908 KB Output is correct
11 Correct 168 ms 24028 KB Output is correct
12 Correct 174 ms 23968 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 45 ms 6200 KB Output is correct
17 Correct 170 ms 23908 KB Output is correct
18 Correct 166 ms 23928 KB Output is correct
19 Correct 165 ms 23932 KB Output is correct
20 Correct 178 ms 23960 KB Output is correct
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
6 Correct 7 ms 1280 KB Output is correct
7 Correct 166 ms 24056 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 180 ms 24016 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 80 ms 14076 KB Output is correct
18 Correct 0 ms 296 KB Output is correct
19 Correct 0 ms 296 KB Output is correct
20 Correct 42 ms 6220 KB Output is correct
21 Correct 166 ms 23928 KB Output is correct
22 Correct 167 ms 24012 KB Output is correct
23 Correct 173 ms 23928 KB Output is correct
24 Correct 166 ms 23944 KB Output is correct
25 Correct 71 ms 14068 KB Output is correct
26 Correct 69 ms 14204 KB Output is correct
27 Correct 172 ms 23924 KB Output is correct
28 Correct 167 ms 23924 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 300 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 304 KB Output is correct
34 Correct 1 ms 300 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 8 ms 1232 KB Output is correct
37 Correct 169 ms 24012 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 1176 KB Output is correct
41 Correct 171 ms 23956 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 4 ms 828 KB Output is correct
45 Correct 81 ms 14084 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 42 ms 6220 KB Output is correct
50 Correct 168 ms 24140 KB Output is correct
51 Correct 166 ms 23924 KB Output is correct
52 Correct 177 ms 24012 KB Output is correct
53 Correct 66 ms 14100 KB Output is correct
54 Correct 66 ms 14068 KB Output is correct
55 Correct 177 ms 23940 KB Output is correct
56 Correct 179 ms 23928 KB Output is correct
57 Correct 89 ms 14076 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 4 ms 796 KB Output is correct
61 Correct 80 ms 14148 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 212 KB Output is correct
65 Correct 44 ms 6256 KB Output is correct
66 Correct 71 ms 14068 KB Output is correct
67 Correct 68 ms 14028 KB Output is correct
68 Correct 67 ms 14000 KB Output is correct
69 Correct 63 ms 14080 KB Output is correct
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
6 Correct 7 ms 1280 KB Output is correct
7 Correct 166 ms 24056 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 180 ms 24016 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 80 ms 14076 KB Output is correct
18 Correct 0 ms 296 KB Output is correct
19 Correct 0 ms 296 KB Output is correct
20 Correct 42 ms 6220 KB Output is correct
21 Correct 166 ms 23928 KB Output is correct
22 Correct 167 ms 24012 KB Output is correct
23 Correct 173 ms 23928 KB Output is correct
24 Correct 166 ms 23944 KB Output is correct
25 Correct 71 ms 14068 KB Output is correct
26 Correct 69 ms 14204 KB Output is correct
27 Correct 172 ms 23924 KB Output is correct
28 Correct 167 ms 23924 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 300 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 304 KB Output is correct
34 Correct 1 ms 300 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 8 ms 1232 KB Output is correct
37 Correct 169 ms 24012 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 1176 KB Output is correct
41 Correct 171 ms 23956 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 4 ms 828 KB Output is correct
45 Correct 81 ms 14084 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 42 ms 6220 KB Output is correct
50 Correct 168 ms 24140 KB Output is correct
51 Correct 166 ms 23924 KB Output is correct
52 Correct 177 ms 24012 KB Output is correct
53 Correct 66 ms 14100 KB Output is correct
54 Correct 66 ms 14068 KB Output is correct
55 Correct 177 ms 23940 KB Output is correct
56 Correct 179 ms 23928 KB Output is correct
57 Correct 89 ms 14076 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 46 ms 6168 KB Output is correct
62 Correct 184 ms 23908 KB Output is correct
63 Correct 174 ms 23944 KB Output is correct
64 Correct 180 ms 23988 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 45 ms 6264 KB Output is correct
67 Correct 168 ms 23908 KB Output is correct
68 Correct 168 ms 24028 KB Output is correct
69 Correct 174 ms 23968 KB Output is correct
70 Correct 1 ms 296 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 45 ms 6200 KB Output is correct
74 Correct 170 ms 23908 KB Output is correct
75 Correct 166 ms 23928 KB Output is correct
76 Correct 165 ms 23932 KB Output is correct
77 Correct 178 ms 23960 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 4 ms 796 KB Output is correct
81 Correct 80 ms 14148 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 212 KB Output is correct
85 Correct 44 ms 6256 KB Output is correct
86 Correct 71 ms 14068 KB Output is correct
87 Correct 68 ms 14028 KB Output is correct
88 Correct 67 ms 14000 KB Output is correct
89 Correct 63 ms 14080 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 0 ms 296 KB Output is correct
92 Correct 3 ms 792 KB Output is correct
93 Correct 75 ms 14076 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 0 ms 300 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 18 ms 3712 KB Output is correct
98 Correct 67 ms 14100 KB Output is correct
99 Correct 71 ms 14072 KB Output is correct
100 Correct 68 ms 14068 KB Output is correct
101 Correct 65 ms 14072 KB Output is correct
102 Correct 68 ms 14084 KB Output is correct
103 Correct 75 ms 14156 KB Output is correct
104 Correct 71 ms 14076 KB Output is correct
105 Correct 83 ms 14144 KB Output is correct