Submission #1106022

# Submission time Handle Problem Language Result Execution time Memory
1106022 2024-10-28T23:01:59 Z snpmrnhlol Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
181 ms 28232 KB
#include "supertrees.h"
#include <vector>
#include <iostream>
using namespace std;
const int N = 1e3;
vector <int> e[N];
bool vis[N];
bool vis2[N];
vector <int> comp;
vector <int> cycle;
vector <int> comp2;
void dfs(int node){
    vis[node] = 1;
    comp.push_back(node);
    for(auto i:e[node]){
        if(!vis[i]){
            dfs(i);
        }
    }
}
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	std::vector<std::vector<int>> ans;
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		ans.push_back(row);
	}
	for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            if(p[i][j] && i != j){
                e[i].push_back(j);
            }
        }
	}
	bool ok = 1;
	for(int i = 0;i < n;i++){
        if(!vis[i]){
            comp.clear();
            dfs(i);
            bool de = 0;
            for(auto j:comp){
                for(auto k:comp){
                    if(p[j][k] == 2)de = 1;
                }
            }
            ///can exist double edge or not
            if(de == 0){
                ///create a tree
                for(auto j:comp){
                    ans[j][comp[0]] = 1;
                    ans[comp[0]][j] = 1;
                }
                ans[comp[0]][comp[0]] = 0;
                for(auto j:comp){
                    for(auto k:comp){
                        if(p[j][k] != 1)ok = 0;
                    }
                }
            }else{
                ///create a single cactus
                cycle.clear();
                for(auto j:comp){
                    if(vis2[j])continue;
                    vis2[j] = 1;
                    comp2.clear();
                    comp2.push_back(j);
                    for(auto k:comp){
                        if(vis2[k])continue;
                        if(p[j][k] == 1){
                            vis2[k] = 1;
                            comp2.push_back(k);
                        }
                    }
                    for(auto k:comp2){
                        for(auto q:comp2){
                            if(p[k][q] != 1)ok = 0;
                        }
                    }
                    for(auto k:comp2){
                        for(auto q:comp){
                            if(vis2[q])continue;
                            if(p[k][q] != 2)ok = 0;
                        }
                    }
                    for(int k = 0;k < (int)comp2.size() - 1;k++){
                        ans[comp2[k]][comp2[k + 1]] = 1;
                        ans[comp2[k + 1]][comp2[k]] = 1;
                    }
                    cycle.push_back(comp2[0]);
                }
                if(cycle.size() < 3)ok = 0;
                for(int k = 0;k < (int)cycle.size();k++){
                    ans[cycle[k]][cycle[(k + 1)%(int)cycle.size()]] = 1;
                    ans[cycle[(k + 1)%(int)cycle.size()]][cycle[k]] = 1;
                }
            }
            for(auto j:comp){
                for(int i = 0;i < n;i++){
                    if(vis[i])continue;
                    if(p[j][i] >= 1)ok = 0;
                }
            }
        }
    }
    if(!ok)return 0;
	build(ans);
	return 1;
}
/**
4
1 1 2 2
1 1 2 2
2 2 1 2
2 2 2 1
**/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 6 ms 1616 KB Output is correct
7 Correct 138 ms 28232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 6 ms 1616 KB Output is correct
7 Correct 138 ms 28232 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 6 ms 1360 KB Output is correct
13 Correct 120 ms 23980 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 4 ms 1104 KB Output is correct
17 Correct 73 ms 16712 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 35 ms 6480 KB Output is correct
21 Correct 121 ms 24496 KB Output is correct
22 Correct 127 ms 24036 KB Output is correct
23 Correct 131 ms 26152 KB Output is correct
24 Correct 131 ms 24100 KB Output is correct
25 Correct 57 ms 14632 KB Output is correct
26 Correct 58 ms 14152 KB Output is correct
27 Correct 140 ms 27184 KB Output is correct
28 Correct 123 ms 24136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 6 ms 1360 KB Output is correct
9 Correct 146 ms 24136 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 6 ms 1616 KB Output is correct
13 Correct 137 ms 28076 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 4 ms 1104 KB Output is correct
17 Correct 74 ms 16648 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 33 ms 6472 KB Output is correct
22 Correct 139 ms 24520 KB Output is correct
23 Correct 135 ms 23976 KB Output is correct
24 Correct 181 ms 27208 KB Output is correct
25 Correct 56 ms 14120 KB Output is correct
26 Correct 60 ms 14756 KB Output is correct
27 Correct 123 ms 24100 KB Output is correct
28 Correct 143 ms 26084 KB Output is correct
29 Correct 56 ms 14136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 33 ms 6472 KB Output is correct
5 Correct 130 ms 24484 KB Output is correct
6 Correct 124 ms 24136 KB Output is correct
7 Correct 131 ms 26184 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 34 ms 6256 KB Output is correct
10 Correct 120 ms 24648 KB Output is correct
11 Correct 121 ms 24136 KB Output is correct
12 Correct 139 ms 27212 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 31 ms 6648 KB Output is correct
17 Correct 122 ms 24616 KB Output is correct
18 Correct 133 ms 24616 KB Output is correct
19 Correct 118 ms 24140 KB Output is correct
20 Correct 116 ms 23972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 6 ms 1616 KB Output is correct
7 Correct 138 ms 28232 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 6 ms 1360 KB Output is correct
13 Correct 120 ms 23980 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 4 ms 1104 KB Output is correct
17 Correct 73 ms 16712 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 35 ms 6480 KB Output is correct
21 Correct 121 ms 24496 KB Output is correct
22 Correct 127 ms 24036 KB Output is correct
23 Correct 131 ms 26152 KB Output is correct
24 Correct 131 ms 24100 KB Output is correct
25 Correct 57 ms 14632 KB Output is correct
26 Correct 58 ms 14152 KB Output is correct
27 Correct 140 ms 27184 KB Output is correct
28 Correct 123 ms 24136 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 504 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 6 ms 1360 KB Output is correct
37 Correct 146 ms 24136 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 6 ms 1616 KB Output is correct
41 Correct 137 ms 28076 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 4 ms 1104 KB Output is correct
45 Correct 74 ms 16648 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 33 ms 6472 KB Output is correct
50 Correct 139 ms 24520 KB Output is correct
51 Correct 135 ms 23976 KB Output is correct
52 Correct 181 ms 27208 KB Output is correct
53 Correct 56 ms 14120 KB Output is correct
54 Correct 60 ms 14756 KB Output is correct
55 Correct 123 ms 24100 KB Output is correct
56 Correct 143 ms 26084 KB Output is correct
57 Correct 56 ms 14136 KB Output is correct
58 Correct 1 ms 504 KB Output is correct
59 Correct 1 ms 336 KB Output is correct
60 Correct 4 ms 1104 KB Output is correct
61 Correct 70 ms 18348 KB Output is correct
62 Correct 1 ms 336 KB Output is correct
63 Correct 1 ms 592 KB Output is correct
64 Correct 1 ms 336 KB Output is correct
65 Correct 31 ms 6444 KB Output is correct
66 Correct 56 ms 14652 KB Output is correct
67 Correct 56 ms 14632 KB Output is correct
68 Correct 65 ms 14372 KB Output is correct
69 Correct 56 ms 14152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 6 ms 1616 KB Output is correct
7 Correct 138 ms 28232 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 6 ms 1360 KB Output is correct
13 Correct 120 ms 23980 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 4 ms 1104 KB Output is correct
17 Correct 73 ms 16712 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 35 ms 6480 KB Output is correct
21 Correct 121 ms 24496 KB Output is correct
22 Correct 127 ms 24036 KB Output is correct
23 Correct 131 ms 26152 KB Output is correct
24 Correct 131 ms 24100 KB Output is correct
25 Correct 57 ms 14632 KB Output is correct
26 Correct 58 ms 14152 KB Output is correct
27 Correct 140 ms 27184 KB Output is correct
28 Correct 123 ms 24136 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 504 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 6 ms 1360 KB Output is correct
37 Correct 146 ms 24136 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 6 ms 1616 KB Output is correct
41 Correct 137 ms 28076 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 4 ms 1104 KB Output is correct
45 Correct 74 ms 16648 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 33 ms 6472 KB Output is correct
50 Correct 139 ms 24520 KB Output is correct
51 Correct 135 ms 23976 KB Output is correct
52 Correct 181 ms 27208 KB Output is correct
53 Correct 56 ms 14120 KB Output is correct
54 Correct 60 ms 14756 KB Output is correct
55 Correct 123 ms 24100 KB Output is correct
56 Correct 143 ms 26084 KB Output is correct
57 Correct 56 ms 14136 KB Output is correct
58 Correct 1 ms 336 KB Output is correct
59 Correct 1 ms 336 KB Output is correct
60 Correct 1 ms 460 KB Output is correct
61 Correct 33 ms 6472 KB Output is correct
62 Correct 130 ms 24484 KB Output is correct
63 Correct 124 ms 24136 KB Output is correct
64 Correct 131 ms 26184 KB Output is correct
65 Correct 1 ms 336 KB Output is correct
66 Correct 34 ms 6256 KB Output is correct
67 Correct 120 ms 24648 KB Output is correct
68 Correct 121 ms 24136 KB Output is correct
69 Correct 139 ms 27212 KB Output is correct
70 Correct 1 ms 336 KB Output is correct
71 Correct 1 ms 336 KB Output is correct
72 Correct 1 ms 336 KB Output is correct
73 Correct 31 ms 6648 KB Output is correct
74 Correct 122 ms 24616 KB Output is correct
75 Correct 133 ms 24616 KB Output is correct
76 Correct 118 ms 24140 KB Output is correct
77 Correct 116 ms 23972 KB Output is correct
78 Correct 1 ms 504 KB Output is correct
79 Correct 1 ms 336 KB Output is correct
80 Correct 4 ms 1104 KB Output is correct
81 Correct 70 ms 18348 KB Output is correct
82 Correct 1 ms 336 KB Output is correct
83 Correct 1 ms 592 KB Output is correct
84 Correct 1 ms 336 KB Output is correct
85 Correct 31 ms 6444 KB Output is correct
86 Correct 56 ms 14652 KB Output is correct
87 Correct 56 ms 14632 KB Output is correct
88 Correct 65 ms 14372 KB Output is correct
89 Correct 56 ms 14152 KB Output is correct
90 Correct 1 ms 336 KB Output is correct
91 Correct 1 ms 336 KB Output is correct
92 Correct 4 ms 1104 KB Output is correct
93 Correct 69 ms 18248 KB Output is correct
94 Correct 1 ms 336 KB Output is correct
95 Correct 1 ms 336 KB Output is correct
96 Correct 1 ms 336 KB Output is correct
97 Correct 14 ms 3880 KB Output is correct
98 Correct 56 ms 14636 KB Output is correct
99 Correct 57 ms 14760 KB Output is correct
100 Correct 54 ms 14248 KB Output is correct
101 Correct 61 ms 14152 KB Output is correct
102 Correct 68 ms 18216 KB Output is correct
103 Correct 66 ms 18248 KB Output is correct
104 Correct 67 ms 18352 KB Output is correct
105 Correct 75 ms 16712 KB Output is correct