Submission #771483

# Submission time Handle Problem Language Result Execution time Memory
771483 2023-07-03T04:32:10 Z ono_de206 Connecting Supertrees (IOI20_supertrees) C++14
21 / 100
171 ms 24060 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;

#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// #define int long long
 
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int mxn = 1010;
int par[mxn];

int get(int x) {
	return (x == par[x] ? x : par[x] = get(par[x]));
}

void unite(int x, int y) {
	x = get(x); y = get(y);
	if(x == y) return;
	par[y] = x;
}

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int>> answer(n, vector<int>(n));
	for(int i = 0; i < n; i++) {
		par[i] = i;
	}
	int mx = 0;
	for (int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(p[i][j] > 0) {
				unite(i, j);
				mx = max(mx, p[i][j]);
			} 
		}
	}
	if(mx == 0) {
		build(answer);
		return 1;
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(p[i][j] == 0 && get(i) == get(j)) {
				return 0;
			}
		}
	}
	vector<int> vis(n);
	for(int i = 0; i < n; i++) {
		if(vis[i]) continue;
		int ls = i, cnt = 1;
		for(int j = i + 1; j < n; j++) {
			if(get(j) == get(i)) {
				answer[ls][j] = answer[j][ls] = 1;
				ls = j;
				vis[j] = 1;
				cnt++;
			}
		}
		if(mx == 2) {
			if(cnt == 2) return 0;
			answer[i][ls] = answer[ls][i] = 1;
		}
	}
	build(answer);
	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 7 ms 1108 KB Output is correct
7 Correct 160 ms 22020 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 7 ms 1108 KB Output is correct
7 Correct 160 ms 22020 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 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 156 ms 21960 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 73 ms 12036 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 46 ms 5708 KB Output is correct
21 Correct 157 ms 21964 KB Output is correct
22 Correct 153 ms 22020 KB Output is correct
23 Correct 157 ms 22040 KB Output is correct
24 Correct 158 ms 22044 KB Output is correct
25 Correct 64 ms 12040 KB Output is correct
26 Correct 67 ms 12036 KB Output is correct
27 Correct 160 ms 21980 KB Output is correct
28 Correct 160 ms 21968 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 1 ms 300 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 7 ms 1208 KB Output is correct
9 Correct 161 ms 23992 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1184 KB Output is correct
13 Correct 159 ms 23940 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 852 KB Output is correct
17 Correct 79 ms 14076 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Incorrect 0 ms 212 KB b[4][4] is not 0
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 41 ms 6212 KB Output is correct
5 Correct 171 ms 24060 KB Output is correct
6 Correct 162 ms 23904 KB Output is correct
7 Correct 161 ms 24012 KB Output is correct
8 Incorrect 1 ms 300 KB b[4][4] is not 0
9 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 7 ms 1108 KB Output is correct
7 Correct 160 ms 22020 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 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 156 ms 21960 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 73 ms 12036 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 46 ms 5708 KB Output is correct
21 Correct 157 ms 21964 KB Output is correct
22 Correct 153 ms 22020 KB Output is correct
23 Correct 157 ms 22040 KB Output is correct
24 Correct 158 ms 22044 KB Output is correct
25 Correct 64 ms 12040 KB Output is correct
26 Correct 67 ms 12036 KB Output is correct
27 Correct 160 ms 21980 KB Output is correct
28 Correct 160 ms 21968 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 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 300 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 304 KB Output is correct
36 Correct 7 ms 1208 KB Output is correct
37 Correct 161 ms 23992 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 7 ms 1184 KB Output is correct
41 Correct 159 ms 23940 KB Output is correct
42 Correct 1 ms 300 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 5 ms 852 KB Output is correct
45 Correct 79 ms 14076 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 304 KB Output is correct
48 Incorrect 0 ms 212 KB b[4][4] is not 0
49 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 7 ms 1108 KB Output is correct
7 Correct 160 ms 22020 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 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 156 ms 21960 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 73 ms 12036 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 46 ms 5708 KB Output is correct
21 Correct 157 ms 21964 KB Output is correct
22 Correct 153 ms 22020 KB Output is correct
23 Correct 157 ms 22040 KB Output is correct
24 Correct 158 ms 22044 KB Output is correct
25 Correct 64 ms 12040 KB Output is correct
26 Correct 67 ms 12036 KB Output is correct
27 Correct 160 ms 21980 KB Output is correct
28 Correct 160 ms 21968 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 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 300 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 304 KB Output is correct
36 Correct 7 ms 1208 KB Output is correct
37 Correct 161 ms 23992 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 7 ms 1184 KB Output is correct
41 Correct 159 ms 23940 KB Output is correct
42 Correct 1 ms 300 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 5 ms 852 KB Output is correct
45 Correct 79 ms 14076 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 304 KB Output is correct
48 Incorrect 0 ms 212 KB b[4][4] is not 0
49 Halted 0 ms 0 KB -