Submission #789668

# Submission time Handle Problem Language Result Execution time Memory
789668 2023-07-21T17:10:50 Z FEDIKUS Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
206 ms 24096 KB
#include "supertrees.h"
#include <vector>
#include<map>
#include<algorithm>

using namespace std;

const int maxn=1010;

int dsu[maxn];
int dsu2[maxn];

int cale(int a,int *dsu){
	return dsu[a]==a ? a:cale(dsu[a],dsu);
}
void join(int a,int b,int *dsu){
	dsu[cale(a,dsu)]=cale(b,dsu);
}

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int>> answer;
	for (int i = 0; i < n; i++) {
		vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}

	for(int i=0;i<n;i++) dsu[i]=i;
	for(int i=0;i<n;i++) dsu2[i]=i;
	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++){
			if(p[i][j]==1) join(i,j,dsu);
			if(p[i][j]==3) return 0;
		}
	}
	for(int i=0;i<n;i++){
		if(i!=cale(i,dsu)){
			answer[i][cale(i,dsu)]=1;
			answer[cale(i,dsu)][i]=1;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++){
			if(p[i][j]==0) if(cale(i,dsu)==cale(j,dsu)) return 0;
			if(p[i][j]==2){
				if(cale(i,dsu)==cale(j,dsu)) return 0;
				join(cale(i,dsu),cale(j,dsu),dsu2);
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++){
			if(p[i][j]==0) if(cale(cale(i,dsu),dsu2)==cale(cale(j,dsu),dsu2)) return 0;
		}
	}
	map<int,vector<int> > kurac;
	for(int i=0;i<n;i++){
		kurac[cale(cale(i,dsu),dsu2)].push_back(cale(i,dsu));
	}
	for(auto i:kurac){
		sort(i.second.begin(),i.second.end());
		i.second.resize(unique(i.second.begin(),i.second.end())-i.second.begin());
		int prev=i.second.back();
		for(int j:i.second){
			if(prev==j) break;
			if(prev!=-1){
				answer[prev][j]=1;
				answer[j][prev]=1;
			}
			prev=j;
		}
	}
	build(answer);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 292 KB Output is correct
2 Correct 1 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 9 ms 1212 KB Output is correct
7 Correct 166 ms 23928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 292 KB Output is correct
2 Correct 1 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 9 ms 1212 KB Output is correct
7 Correct 166 ms 23928 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 9 ms 1204 KB Output is correct
13 Correct 173 ms 24048 KB Output is correct
14 Correct 1 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 90 ms 14060 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 45 ms 6240 KB Output is correct
21 Correct 154 ms 23928 KB Output is correct
22 Correct 196 ms 24044 KB Output is correct
23 Correct 168 ms 23932 KB Output is correct
24 Correct 171 ms 24096 KB Output is correct
25 Correct 68 ms 14056 KB Output is correct
26 Correct 88 ms 14060 KB Output is correct
27 Correct 155 ms 23916 KB Output is correct
28 Correct 163 ms 24044 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 212 KB Output is correct
4 Incorrect 1 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 292 KB Output is correct
2 Correct 1 ms 292 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 41 ms 6220 KB Output is correct
5 Correct 159 ms 23920 KB Output is correct
6 Correct 151 ms 24040 KB Output is correct
7 Correct 206 ms 23896 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 45 ms 6220 KB Output is correct
10 Correct 200 ms 23952 KB Output is correct
11 Correct 165 ms 23912 KB Output is correct
12 Correct 155 ms 23968 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 39 ms 6248 KB Output is correct
17 Correct 149 ms 23916 KB Output is correct
18 Correct 153 ms 23924 KB Output is correct
19 Correct 151 ms 23908 KB Output is correct
20 Correct 161 ms 24088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 292 KB Output is correct
2 Correct 1 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 9 ms 1212 KB Output is correct
7 Correct 166 ms 23928 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 9 ms 1204 KB Output is correct
13 Correct 173 ms 24048 KB Output is correct
14 Correct 1 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 90 ms 14060 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 45 ms 6240 KB Output is correct
21 Correct 154 ms 23928 KB Output is correct
22 Correct 196 ms 24044 KB Output is correct
23 Correct 168 ms 23932 KB Output is correct
24 Correct 171 ms 24096 KB Output is correct
25 Correct 68 ms 14056 KB Output is correct
26 Correct 88 ms 14060 KB Output is correct
27 Correct 155 ms 23916 KB Output is correct
28 Correct 163 ms 24044 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 212 KB Output is correct
32 Incorrect 1 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 292 KB Output is correct
2 Correct 1 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 9 ms 1212 KB Output is correct
7 Correct 166 ms 23928 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 9 ms 1204 KB Output is correct
13 Correct 173 ms 24048 KB Output is correct
14 Correct 1 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 90 ms 14060 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 45 ms 6240 KB Output is correct
21 Correct 154 ms 23928 KB Output is correct
22 Correct 196 ms 24044 KB Output is correct
23 Correct 168 ms 23932 KB Output is correct
24 Correct 171 ms 24096 KB Output is correct
25 Correct 68 ms 14056 KB Output is correct
26 Correct 88 ms 14060 KB Output is correct
27 Correct 155 ms 23916 KB Output is correct
28 Correct 163 ms 24044 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 212 KB Output is correct
32 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -