Submission #1019948

# Submission time Handle Problem Language Result Execution time Memory
1019948 2024-07-11T11:04:03 Z Mardonbekhazratov Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
161 ms 24308 KB
#include "supertrees.h"
#include <vector>

using namespace std;

int n;
bool ok;
vector<int>in;
vector<vector<int>>v,comp;
vector<bool>vis;

void dfs(int x){
	comp[in[x]].push_back(x);
	vis[x]=true;
	for(int i=x+1;i<n;i++){
		if(v[x][i]){
			if(vis[i]) continue;
			in[i]=in[x];
			dfs(i);
		}
	}
}

int construct(vector<vector<int>> p) {
	swap(p,v);
	n=v.size();
	in.resize(n);
	vis.assign(n,false);
	for(int i=0;i<n;i++){
		if(!vis[i]){
			in[i]=comp.size();
			comp.push_back({});
			dfs(i);
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(v[i][j]>0 && in[i]!=in[j] || (in[i]==in[j] && v[i][j]==0) || v[i][j]==3) return 0;
		}
	}
	vector<vector<int>>ans(n,vector<int>(n,0));
	for(auto g:comp){
		vis.assign(n,false);
		vector<int>cycle;
		for(int x:g){
			if(vis[x]) continue;
			vector<int>line;
			for(int j=0;j<n;j++){
				if(v[x][j]==1) line.push_back(j);
			}
			for(int y:line){
				for(int z:line){
					if(v[y][z]!=1) return 0;
				}
				vis[y]=true;
			}
			for(int i=1;i<line.size();i++) ans[line[i]][line[i-1]]=ans[line[i-1]][line[i]]=1;
			cycle.push_back(line[0]);
		}
		if(cycle.size()==2) return 0;
		if(cycle.size()>2){
			for(int i=1;i<cycle.size();i++) ans[cycle[i-1]][cycle[i]]=ans[cycle[i]][cycle[i-1]]=1;
			ans[cycle[0]][cycle.back()]=ans[cycle.back()][cycle[0]]=1;
		}
	}
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:38:17: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   38 |    if(v[i][j]>0 && in[i]!=in[j] || (in[i]==in[j] && v[i][j]==0) || v[i][j]==3) return 0;
supertrees.cpp:57:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |    for(int i=1;i<line.size();i++) ans[line[i]][line[i-1]]=ans[line[i-1]][line[i]]=1;
      |                ~^~~~~~~~~~~~
supertrees.cpp:62:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |    for(int i=1;i<cycle.size();i++) ans[cycle[i-1]][cycle[i]]=ans[cycle[i]][cycle[i-1]]=1;
      |                ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1176 KB Output is correct
7 Correct 118 ms 24052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1176 KB Output is correct
7 Correct 118 ms 24052 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 114 ms 24148 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 56 ms 10112 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 28 ms 6252 KB Output is correct
21 Correct 117 ms 23892 KB Output is correct
22 Correct 161 ms 24144 KB Output is correct
23 Correct 118 ms 23968 KB Output is correct
24 Correct 117 ms 24144 KB Output is correct
25 Correct 56 ms 10232 KB Output is correct
26 Correct 49 ms 10068 KB Output is correct
27 Correct 124 ms 23928 KB Output is correct
28 Correct 117 ms 24172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 424 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 9 ms 1344 KB Output is correct
9 Correct 117 ms 24060 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 5 ms 1368 KB Output is correct
13 Correct 116 ms 24096 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 79 ms 10224 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 28 ms 6248 KB Output is correct
22 Correct 118 ms 23896 KB Output is correct
23 Correct 142 ms 24128 KB Output is correct
24 Correct 119 ms 24144 KB Output is correct
25 Correct 51 ms 14164 KB Output is correct
26 Correct 57 ms 10276 KB Output is correct
27 Correct 111 ms 24148 KB Output is correct
28 Correct 117 ms 24148 KB Output is correct
29 Correct 51 ms 14204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 28 ms 6532 KB Output is correct
5 Correct 127 ms 23964 KB Output is correct
6 Correct 119 ms 24276 KB Output is correct
7 Correct 123 ms 23988 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 28 ms 6260 KB Output is correct
10 Correct 120 ms 24040 KB Output is correct
11 Correct 115 ms 24144 KB Output is correct
12 Correct 122 ms 24120 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 29 ms 6360 KB Output is correct
17 Correct 160 ms 23888 KB Output is correct
18 Correct 121 ms 24308 KB Output is correct
19 Correct 114 ms 23988 KB Output is correct
20 Correct 110 ms 24144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1176 KB Output is correct
7 Correct 118 ms 24052 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 114 ms 24148 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 56 ms 10112 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 28 ms 6252 KB Output is correct
21 Correct 117 ms 23892 KB Output is correct
22 Correct 161 ms 24144 KB Output is correct
23 Correct 118 ms 23968 KB Output is correct
24 Correct 117 ms 24144 KB Output is correct
25 Correct 56 ms 10232 KB Output is correct
26 Correct 49 ms 10068 KB Output is correct
27 Correct 124 ms 23928 KB Output is correct
28 Correct 117 ms 24172 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 424 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 9 ms 1344 KB Output is correct
37 Correct 117 ms 24060 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 5 ms 1368 KB Output is correct
41 Correct 116 ms 24096 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 79 ms 10224 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 28 ms 6248 KB Output is correct
50 Correct 118 ms 23896 KB Output is correct
51 Correct 142 ms 24128 KB Output is correct
52 Correct 119 ms 24144 KB Output is correct
53 Correct 51 ms 14164 KB Output is correct
54 Correct 57 ms 10276 KB Output is correct
55 Correct 111 ms 24148 KB Output is correct
56 Correct 117 ms 24148 KB Output is correct
57 Correct 51 ms 14204 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 2 ms 604 KB Output is correct
61 Correct 54 ms 10104 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 39 ms 6236 KB Output is correct
66 Correct 51 ms 10064 KB Output is correct
67 Correct 54 ms 10224 KB Output is correct
68 Correct 48 ms 10068 KB Output is correct
69 Correct 50 ms 14160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1176 KB Output is correct
7 Correct 118 ms 24052 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 114 ms 24148 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 56 ms 10112 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 28 ms 6252 KB Output is correct
21 Correct 117 ms 23892 KB Output is correct
22 Correct 161 ms 24144 KB Output is correct
23 Correct 118 ms 23968 KB Output is correct
24 Correct 117 ms 24144 KB Output is correct
25 Correct 56 ms 10232 KB Output is correct
26 Correct 49 ms 10068 KB Output is correct
27 Correct 124 ms 23928 KB Output is correct
28 Correct 117 ms 24172 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 424 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 9 ms 1344 KB Output is correct
37 Correct 117 ms 24060 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 5 ms 1368 KB Output is correct
41 Correct 116 ms 24096 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 79 ms 10224 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 28 ms 6248 KB Output is correct
50 Correct 118 ms 23896 KB Output is correct
51 Correct 142 ms 24128 KB Output is correct
52 Correct 119 ms 24144 KB Output is correct
53 Correct 51 ms 14164 KB Output is correct
54 Correct 57 ms 10276 KB Output is correct
55 Correct 111 ms 24148 KB Output is correct
56 Correct 117 ms 24148 KB Output is correct
57 Correct 51 ms 14204 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 344 KB Output is correct
61 Correct 28 ms 6532 KB Output is correct
62 Correct 127 ms 23964 KB Output is correct
63 Correct 119 ms 24276 KB Output is correct
64 Correct 123 ms 23988 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 28 ms 6260 KB Output is correct
67 Correct 120 ms 24040 KB Output is correct
68 Correct 115 ms 24144 KB Output is correct
69 Correct 122 ms 24120 KB Output is correct
70 Correct 0 ms 344 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 29 ms 6360 KB Output is correct
74 Correct 160 ms 23888 KB Output is correct
75 Correct 121 ms 24308 KB Output is correct
76 Correct 114 ms 23988 KB Output is correct
77 Correct 110 ms 24144 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 2 ms 604 KB Output is correct
81 Correct 54 ms 10104 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 39 ms 6236 KB Output is correct
86 Correct 51 ms 10064 KB Output is correct
87 Correct 54 ms 10224 KB Output is correct
88 Correct 48 ms 10068 KB Output is correct
89 Correct 50 ms 14160 KB Output is correct
90 Correct 0 ms 344 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 2 ms 604 KB Output is correct
93 Correct 54 ms 10236 KB Output is correct
94 Correct 0 ms 344 KB Output is correct
95 Correct 1 ms 344 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 15 ms 2668 KB Output is correct
98 Correct 49 ms 10064 KB Output is correct
99 Correct 52 ms 10068 KB Output is correct
100 Correct 47 ms 10064 KB Output is correct
101 Correct 47 ms 10236 KB Output is correct
102 Correct 46 ms 10324 KB Output is correct
103 Correct 49 ms 10116 KB Output is correct
104 Correct 47 ms 10324 KB Output is correct
105 Correct 56 ms 10072 KB Output is correct