Submission #783589

# Submission time Handle Problem Language Result Execution time Memory
783589 2023-07-15T04:37:35 Z mindiyak Connecting Supertrees (IOI20_supertrees) C++14
21 / 100
209 ms 22064 KB
#include "supertrees.h"
#include <vector>
#include <iostream>

#define pb push_back

using namespace std;
vector<int> head;
vector<int> leaf;

int find_head(int val){
	if(head[val] == val)
	    return val;
	int temp = find_head(head[val]);
	head[val] = temp;
	return temp;
}

int find_leaf(int val){
	if(leaf[val] == val)
	    return val;
	int temp = find_leaf(leaf[val]);
	leaf[val] = temp;
	return temp;
}

int construct(vector<vector<int>> p) {
    // cout << "started" << endl;
	int n = p.size();

	vector<vector<int>> ans;
	vector<int> temp(n,0);
	for (int i = 0; i < n; i++) {
		ans.pb(temp);
		head.pb(i);
		leaf.pb(i);
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(p[i][j] >= 1){
				int c = min(i,j),d = max(i,j);

				int h_c = find_head(c);
				int h_d = find_head(d);
				int l_c = find_leaf(c);
				int l_d = find_leaf(d);

				if(h_c != h_d){
				    ans[h_c][h_d] = 1;
				    ans[h_d][h_c] = 1;
				}
				head[h_d] = h_c;
				leaf[h_c] = l_d;
			} 
		}
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			int c = min(i,j),d = max(i,j);
			int h_c = find_head(c);
			int h_d = find_head(d);

			if(p[i][j] == 2){
				int l_c = find_leaf(c);
				int l_d = find_leaf(d);
				ans[h_c][l_d] = 1;
				ans[l_d][h_c] = 1;
				if(h_c == h_d or l_c != l_d){
					return 0;
				}
			}
			
			if(p[i][j] == 0 and h_c == h_d){
				return 0;
			}
			if(p[i][j] == 1 and h_c != h_d){
				return 0;
			}
		}
	}


	build(ans);
// 	cout << "finish" << endl;
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:46:9: warning: unused variable 'l_c' [-Wunused-variable]
   46 |     int l_c = find_leaf(c);
      |         ^~~
# 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1096 KB Output is correct
7 Correct 159 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1096 KB Output is correct
7 Correct 159 ms 22020 KB Output is correct
8 Correct 1 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 6 ms 1108 KB Output is correct
13 Correct 152 ms 22032 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 79 ms 12048 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 40 ms 5764 KB Output is correct
21 Correct 209 ms 22020 KB Output is correct
22 Correct 176 ms 22036 KB Output is correct
23 Correct 163 ms 22064 KB Output is correct
24 Correct 155 ms 22020 KB Output is correct
25 Correct 65 ms 12044 KB Output is correct
26 Correct 59 ms 12056 KB Output is correct
27 Correct 194 ms 22020 KB Output is correct
28 Correct 174 ms 22004 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 1 ms 256 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Answer gives possible 0 while actual possible 1
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Answer gives possible 0 while actual possible 1
3 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1096 KB Output is correct
7 Correct 159 ms 22020 KB Output is correct
8 Correct 1 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 6 ms 1108 KB Output is correct
13 Correct 152 ms 22032 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 79 ms 12048 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 40 ms 5764 KB Output is correct
21 Correct 209 ms 22020 KB Output is correct
22 Correct 176 ms 22036 KB Output is correct
23 Correct 163 ms 22064 KB Output is correct
24 Correct 155 ms 22020 KB Output is correct
25 Correct 65 ms 12044 KB Output is correct
26 Correct 59 ms 12056 KB Output is correct
27 Correct 194 ms 22020 KB Output is correct
28 Correct 174 ms 22004 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Incorrect 0 ms 212 KB Answer gives possible 0 while actual possible 1
34 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1096 KB Output is correct
7 Correct 159 ms 22020 KB Output is correct
8 Correct 1 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 6 ms 1108 KB Output is correct
13 Correct 152 ms 22032 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 79 ms 12048 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 40 ms 5764 KB Output is correct
21 Correct 209 ms 22020 KB Output is correct
22 Correct 176 ms 22036 KB Output is correct
23 Correct 163 ms 22064 KB Output is correct
24 Correct 155 ms 22020 KB Output is correct
25 Correct 65 ms 12044 KB Output is correct
26 Correct 59 ms 12056 KB Output is correct
27 Correct 194 ms 22020 KB Output is correct
28 Correct 174 ms 22004 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Incorrect 0 ms 212 KB Answer gives possible 0 while actual possible 1
34 Halted 0 ms 0 KB -