Submission #986612

# Submission time Handle Problem Language Result Execution time Memory
986612 2024-05-20T21:13:41 Z aaaaaarroz Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
178 ms 38152 KB
    #include "supertrees.h"
    #include<bits/stdc++.h>
    using namespace std;
    #define sz(a) (int)(a.size())
    int p[1111][1111],q[1111][1111],ans[1111][1111];
    void add(int v,int u){
    	ans[v][u] = ans[u][v] = 1;
    }
    int construct(vector<vector<int>> P) {
    	int n = sz(P);
    	for (int i=0;i<n;i++){
    		if(P[i][i] != 1)return 0;
    		for(int j=0;j<n;j++){
    			q[i][j] = ans[i][j] = 0;
    			p[i][j] = P[i][j];
    			if(p[i][j] == 3)return 0;
    		}
    	}
    	//find all nodes connected to 1
    	//then nodes with p(1,v) = 1
    	//this has to form a tree
    	//repeat forming many trees then link the trees in a cycle
    	vector<int>ded(n,0);
    	for(int v=0;v<n;v++){
    		if(ded[v])continue;
    		vector<int>comp;
    		vector<bool>incomp(n,0);
    		for(int j=0;j<n;j++){
    			if(ded[j])continue;
    			if(p[v][j]){
    				incomp[j] = 1;
    				comp.push_back(j);
    				ded[j] = 1;
    			}
    		}
    		for(int x:comp){
    			for(int y:comp){
    				if(!p[x][y])return 0;
    			}
    		}
    		vector<vector<int>>trees;
    		while(!comp.empty()){
    			int v = comp[0];
    			vector<int>tree,tmp;
    			for(int u:comp){
    				if(p[u][v] == 1)tree.push_back(u);
    				else tmp.push_back(u);
    			}
    			trees.push_back(tree);
    			comp = tmp;
    		}
    		int ss = sz(trees);
    		if(ss==2)return 0;
    		if(ss > 1)add(trees[0][0],trees[ss-1][0]);
    		for(int i=0;i<ss;i++){
    			if(i+1<sz(trees))add(trees[i][0],trees[i+1][0]);
    			for(int j=0;j+1<sz(trees[i]);j++)add(trees[i][j],trees[i][j+1]);
     
    			vector<bool>intree(n,0);
    			for(int x:trees[i])intree[x] = 1;
    			for(int x:trees[i]){
    				for(int y:trees[i])q[x][y] = 1;
    				for(int j=0;j<n;j++){
    					if(incomp[j] && !intree[j])q[x][j] = q[j][x] = 2;
    				}
    			}
    		}
    	}
    	for(int i=0;i<n;i++){
    		for(int j=0;j<n;j++){
    			if(q[i][j] != p[i][j])return 0;
    		}
    	}
    	vector<vector<int>>fin(n);
    	for(int i=0;i<n;i++){
    		fin[i].assign(n,0);
    		for(int j=0;j<n;j++)fin[i][j] = ans[i][j];
    	}
    	build(fin);
    	return 1;
    }
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 10 ms 3932 KB Output is correct
7 Correct 161 ms 37180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 10 ms 3932 KB Output is correct
7 Correct 161 ms 37180 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 10 ms 3960 KB Output is correct
13 Correct 163 ms 37044 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 4 ms 7084 KB Output is correct
17 Correct 70 ms 23216 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 0 ms 444 KB Output is correct
20 Correct 40 ms 12732 KB Output is correct
21 Correct 159 ms 37556 KB Output is correct
22 Correct 158 ms 38020 KB Output is correct
23 Correct 155 ms 38020 KB Output is correct
24 Correct 158 ms 37456 KB Output is correct
25 Correct 72 ms 23828 KB Output is correct
26 Correct 68 ms 23244 KB Output is correct
27 Correct 161 ms 37072 KB Output is correct
28 Correct 153 ms 37140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2488 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 8 ms 4184 KB Output is correct
9 Correct 157 ms 37204 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 8 ms 3784 KB Output is correct
13 Correct 173 ms 37460 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 4 ms 3420 KB Output is correct
17 Correct 83 ms 23636 KB Output is correct
18 Correct 1 ms 432 KB Output is correct
19 Correct 1 ms 504 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 41 ms 12896 KB Output is correct
22 Correct 159 ms 37200 KB Output is correct
23 Correct 175 ms 37504 KB Output is correct
24 Correct 157 ms 37672 KB Output is correct
25 Correct 72 ms 24204 KB Output is correct
26 Correct 88 ms 24148 KB Output is correct
27 Correct 154 ms 37108 KB Output is correct
28 Correct 168 ms 38012 KB Output is correct
29 Correct 63 ms 23292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 2596 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 40 ms 12892 KB Output is correct
5 Correct 166 ms 38044 KB Output is correct
6 Correct 163 ms 37664 KB Output is correct
7 Correct 165 ms 37012 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 46 ms 12928 KB Output is correct
10 Correct 175 ms 37936 KB Output is correct
11 Correct 153 ms 36944 KB Output is correct
12 Correct 178 ms 37460 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 40 ms 12728 KB Output is correct
17 Correct 157 ms 38152 KB Output is correct
18 Correct 163 ms 37716 KB Output is correct
19 Correct 172 ms 38080 KB Output is correct
20 Correct 157 ms 37076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 10 ms 3932 KB Output is correct
7 Correct 161 ms 37180 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 10 ms 3960 KB Output is correct
13 Correct 163 ms 37044 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 4 ms 7084 KB Output is correct
17 Correct 70 ms 23216 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 0 ms 444 KB Output is correct
20 Correct 40 ms 12732 KB Output is correct
21 Correct 159 ms 37556 KB Output is correct
22 Correct 158 ms 38020 KB Output is correct
23 Correct 155 ms 38020 KB Output is correct
24 Correct 158 ms 37456 KB Output is correct
25 Correct 72 ms 23828 KB Output is correct
26 Correct 68 ms 23244 KB Output is correct
27 Correct 161 ms 37072 KB Output is correct
28 Correct 153 ms 37140 KB Output is correct
29 Correct 1 ms 2488 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 1 ms 856 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 8 ms 4184 KB Output is correct
37 Correct 157 ms 37204 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 8 ms 3784 KB Output is correct
41 Correct 173 ms 37460 KB Output is correct
42 Correct 1 ms 2392 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 4 ms 3420 KB Output is correct
45 Correct 83 ms 23636 KB Output is correct
46 Correct 1 ms 432 KB Output is correct
47 Correct 1 ms 504 KB Output is correct
48 Correct 1 ms 2652 KB Output is correct
49 Correct 41 ms 12896 KB Output is correct
50 Correct 159 ms 37200 KB Output is correct
51 Correct 175 ms 37504 KB Output is correct
52 Correct 157 ms 37672 KB Output is correct
53 Correct 72 ms 24204 KB Output is correct
54 Correct 88 ms 24148 KB Output is correct
55 Correct 154 ms 37108 KB Output is correct
56 Correct 168 ms 38012 KB Output is correct
57 Correct 63 ms 23292 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 444 KB Output is correct
60 Correct 4 ms 3672 KB Output is correct
61 Correct 71 ms 23160 KB Output is correct
62 Correct 0 ms 440 KB Output is correct
63 Correct 1 ms 2648 KB Output is correct
64 Correct 1 ms 4440 KB Output is correct
65 Correct 40 ms 12872 KB Output is correct
66 Correct 64 ms 24148 KB Output is correct
67 Correct 63 ms 24064 KB Output is correct
68 Correct 63 ms 23296 KB Output is correct
69 Correct 68 ms 23592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 10 ms 3932 KB Output is correct
7 Correct 161 ms 37180 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 10 ms 3960 KB Output is correct
13 Correct 163 ms 37044 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 4 ms 7084 KB Output is correct
17 Correct 70 ms 23216 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 0 ms 444 KB Output is correct
20 Correct 40 ms 12732 KB Output is correct
21 Correct 159 ms 37556 KB Output is correct
22 Correct 158 ms 38020 KB Output is correct
23 Correct 155 ms 38020 KB Output is correct
24 Correct 158 ms 37456 KB Output is correct
25 Correct 72 ms 23828 KB Output is correct
26 Correct 68 ms 23244 KB Output is correct
27 Correct 161 ms 37072 KB Output is correct
28 Correct 153 ms 37140 KB Output is correct
29 Correct 1 ms 2488 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 1 ms 856 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 8 ms 4184 KB Output is correct
37 Correct 157 ms 37204 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 8 ms 3784 KB Output is correct
41 Correct 173 ms 37460 KB Output is correct
42 Correct 1 ms 2392 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 4 ms 3420 KB Output is correct
45 Correct 83 ms 23636 KB Output is correct
46 Correct 1 ms 432 KB Output is correct
47 Correct 1 ms 504 KB Output is correct
48 Correct 1 ms 2652 KB Output is correct
49 Correct 41 ms 12896 KB Output is correct
50 Correct 159 ms 37200 KB Output is correct
51 Correct 175 ms 37504 KB Output is correct
52 Correct 157 ms 37672 KB Output is correct
53 Correct 72 ms 24204 KB Output is correct
54 Correct 88 ms 24148 KB Output is correct
55 Correct 154 ms 37108 KB Output is correct
56 Correct 168 ms 38012 KB Output is correct
57 Correct 63 ms 23292 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 2596 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Correct 40 ms 12892 KB Output is correct
62 Correct 166 ms 38044 KB Output is correct
63 Correct 163 ms 37664 KB Output is correct
64 Correct 165 ms 37012 KB Output is correct
65 Correct 1 ms 2392 KB Output is correct
66 Correct 46 ms 12928 KB Output is correct
67 Correct 175 ms 37936 KB Output is correct
68 Correct 153 ms 36944 KB Output is correct
69 Correct 178 ms 37460 KB Output is correct
70 Correct 1 ms 2396 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 1 ms 2392 KB Output is correct
73 Correct 40 ms 12728 KB Output is correct
74 Correct 157 ms 38152 KB Output is correct
75 Correct 163 ms 37716 KB Output is correct
76 Correct 172 ms 38080 KB Output is correct
77 Correct 157 ms 37076 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Correct 0 ms 444 KB Output is correct
80 Correct 4 ms 3672 KB Output is correct
81 Correct 71 ms 23160 KB Output is correct
82 Correct 0 ms 440 KB Output is correct
83 Correct 1 ms 2648 KB Output is correct
84 Correct 1 ms 4440 KB Output is correct
85 Correct 40 ms 12872 KB Output is correct
86 Correct 64 ms 24148 KB Output is correct
87 Correct 63 ms 24064 KB Output is correct
88 Correct 63 ms 23296 KB Output is correct
89 Correct 68 ms 23592 KB Output is correct
90 Correct 1 ms 4444 KB Output is correct
91 Correct 1 ms 4444 KB Output is correct
92 Correct 3 ms 4700 KB Output is correct
93 Correct 61 ms 10160 KB Output is correct
94 Correct 1 ms 344 KB Output is correct
95 Correct 1 ms 348 KB Output is correct
96 Correct 1 ms 348 KB Output is correct
97 Correct 14 ms 3160 KB Output is correct
98 Correct 56 ms 10880 KB Output is correct
99 Correct 58 ms 12116 KB Output is correct
100 Correct 57 ms 12816 KB Output is correct
101 Correct 65 ms 17236 KB Output is correct
102 Correct 58 ms 14352 KB Output is correct
103 Correct 66 ms 14208 KB Output is correct
104 Correct 63 ms 14220 KB Output is correct
105 Correct 59 ms 14204 KB Output is correct