Submission #825968

# Submission time Handle Problem Language Result Execution time Memory
825968 2023-08-15T09:37:33 Z amunduzbaev Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
177 ms 24064 KB
#include "supertrees.h"

#include "bits/stdc++.h"
using namespace std;

int construct(vector<vector<int>> p) {
	int n = p.size();
	
	vector<int> v;
	vector<int> used(n);
	function<void(int)> dfs = [&](int u){
		v.push_back(u);
		used[u] = 1;
		for(int x=0;x<n;x++){
			if(p[u][x] && !used[x]){
				dfs(x);
			}
		}
	};
	
	vector<vector<int>> ans(n, vector<int>(n, 0));
	
	for(int i=0;i<n;i++){
		if(used[i]) continue;
		dfs(i);
		
		for(auto x : v){
			for(auto y : v){
				if(!p[x][y]){
					return 0;
				}
				if(p[x][y] == 3){
					return 0;
				}
			}
		}
		
		
		vector<int> c(n), one;
		int last = 0;
		function<void(int)> dfs = [&](int u){
			one.push_back(u);
			c[u] = last;
			for(int x=0;x<n;x++){
				if(!c[x] && p[u][x] == 1){
					ans[u][x] = ans[x][u] = 1;
					dfs(x);
				}
			}
		};
		
		vector<int> cyc;
		for(auto u : v){
			if(c[u]) continue;
			last++;
			dfs(u);
			for(auto x : one){
				for(auto y : one){
					if(p[x][y] != 1) return 0;
				}
			}
			
			cyc.push_back(u);
			one.clear();
		}
		
		last = cyc.back();
		for(auto x : cyc){
			if(x != last) ans[x][last] = ans[last][x] = 1;
			last = x;
		}
		
		v.clear();
	}
	
	build(ans);
	
	return 1;
}
# 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 151 ms 24052 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 151 ms 24052 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 304 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 6 ms 1212 KB Output is correct
13 Correct 149 ms 23920 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 72 ms 14120 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 38 ms 6220 KB Output is correct
21 Correct 152 ms 23936 KB Output is correct
22 Correct 150 ms 23920 KB Output is correct
23 Correct 162 ms 24040 KB Output is correct
24 Correct 156 ms 24008 KB Output is correct
25 Correct 67 ms 14084 KB Output is correct
26 Correct 60 ms 14088 KB Output is correct
27 Correct 171 ms 23920 KB Output is correct
28 Correct 148 ms 23992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 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 39 ms 6228 KB Output is correct
5 Correct 152 ms 24016 KB Output is correct
6 Correct 152 ms 23924 KB Output is correct
7 Correct 154 ms 23936 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 40 ms 6256 KB Output is correct
10 Correct 149 ms 23952 KB Output is correct
11 Correct 159 ms 23968 KB Output is correct
12 Correct 167 ms 24064 KB Output is correct
13 Correct 0 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 38 ms 6192 KB Output is correct
17 Correct 177 ms 23936 KB Output is correct
18 Correct 177 ms 24056 KB Output is correct
19 Correct 172 ms 23900 KB Output is correct
20 Correct 155 ms 23952 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 151 ms 24052 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 304 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 6 ms 1212 KB Output is correct
13 Correct 149 ms 23920 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 72 ms 14120 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 38 ms 6220 KB Output is correct
21 Correct 152 ms 23936 KB Output is correct
22 Correct 150 ms 23920 KB Output is correct
23 Correct 162 ms 24040 KB Output is correct
24 Correct 156 ms 24008 KB Output is correct
25 Correct 67 ms 14084 KB Output is correct
26 Correct 60 ms 14088 KB Output is correct
27 Correct 171 ms 23920 KB Output is correct
28 Correct 148 ms 23992 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 304 KB Output is correct
31 Correct 0 ms 296 KB Output is correct
32 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 151 ms 24052 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 304 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 6 ms 1212 KB Output is correct
13 Correct 149 ms 23920 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 72 ms 14120 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 38 ms 6220 KB Output is correct
21 Correct 152 ms 23936 KB Output is correct
22 Correct 150 ms 23920 KB Output is correct
23 Correct 162 ms 24040 KB Output is correct
24 Correct 156 ms 24008 KB Output is correct
25 Correct 67 ms 14084 KB Output is correct
26 Correct 60 ms 14088 KB Output is correct
27 Correct 171 ms 23920 KB Output is correct
28 Correct 148 ms 23992 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 304 KB Output is correct
31 Correct 0 ms 296 KB Output is correct
32 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -