Submission #800060

# Submission time Handle Problem Language Result Execution time Memory
800060 2023-08-01T09:40:02 Z alvingogo Connecting Supertrees (IOI20_supertrees) C++14
56 / 100
195 ms 22156 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;

struct DSU{
	vector<int> bo;
	void init(int x){
		bo.resize(x);
		iota(bo.begin(),bo.end(),0);
	}
	int find(int x){
		return bo[x]==x?x:bo[x]=find(bo[x]);
	}
	void merge(int x,int y){
		x=find(x);
		y=find(y);
		bo[x]=y;
	}
}dsu,dsu2;
int construct(vector<vector<int> > p) {
	int n=p.size();
	dsu.init(n);
	dsu2.init(n);
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(p[i][j]){
				dsu.merge(i,j);
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if((p[i][j]>0) + (dsu.find(i)==dsu.find(j))==1){
				return 0;
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(p[i][j]==1){
				dsu2.merge(i,j);
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(p[i][j]){
				if((p[i][j]==1) + (dsu2.find(i)==dsu2.find(j))==1){
					return 0;
				}
			}	
		}
	}
	vector<int> val(n);
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(dsu.find(i)==dsu.find(j)){
				if(dsu2.find(i)!=dsu2.find(j)){
					if(val[dsu.find(i)] && val[dsu.find(i)]!=p[i][j]){
						return 0;
					}
					val[dsu.find(i)]=p[i][j];
				}
			}
		}
	}
	vector<vector<int> > vx(n);
	vector<vector<int> > bd(n,vector<int>(n));
	for(int i=0;i<n;i++){
		if(i!=dsu2.find(i)){
			bd[i][dsu2.find(i)]=bd[dsu2.find(i)][i]=1;
		}
		else{
			vx[dsu.find(i)].push_back(i);
		}
	}
	for(int i=0;i<n;i++){
		int y=vx[i].size();
		if(y>=2){
			if(val[i]==0){
				return 0;
			}
			if(val[i]==2){
				for(int j=0;j<y;j++){
					bd[vx[i][j]][vx[i][(j+1)%y]]=bd[vx[i][(j+1)%y]][vx[i][j]]=1;
				}
			}
			else if(val[i]==3){
				if(y<=3){
					return 0;
				}
				for(int j=0;j<y;j++){
					bd[vx[i][j]][vx[i][(j+1)%y]]=bd[vx[i][(j+1)%y]][vx[i][j]]=1;
				}
				bd[vx[i][0]][vx[i][2]]=bd[vx[i][2]][vx[i][0]]=1;
			}
		}
	}
	build(bd);
	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 162 ms 21984 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 162 ms 21984 KB Output is correct
8 Correct 0 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 0 ms 212 KB Output is correct
12 Correct 7 ms 1184 KB Output is correct
13 Correct 165 ms 22084 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 71 ms 8196 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 5728 KB Output is correct
21 Correct 156 ms 22000 KB Output is correct
22 Correct 165 ms 22020 KB Output is correct
23 Correct 163 ms 22020 KB Output is correct
24 Correct 152 ms 22020 KB Output is correct
25 Correct 57 ms 8072 KB Output is correct
26 Correct 56 ms 8080 KB Output is correct
27 Correct 183 ms 22020 KB Output is correct
28 Correct 167 ms 22156 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 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 1 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 Correct 39 ms 5776 KB Output is correct
5 Correct 161 ms 22144 KB Output is correct
6 Correct 155 ms 22016 KB Output is correct
7 Correct 161 ms 22056 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 39 ms 5740 KB Output is correct
10 Correct 162 ms 22024 KB Output is correct
11 Correct 180 ms 22036 KB Output is correct
12 Correct 166 ms 21988 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 39 ms 5708 KB Output is correct
17 Correct 155 ms 22056 KB Output is correct
18 Correct 158 ms 22032 KB Output is correct
19 Correct 166 ms 22028 KB Output is correct
20 Correct 195 ms 22016 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 162 ms 21984 KB Output is correct
8 Correct 0 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 0 ms 212 KB Output is correct
12 Correct 7 ms 1184 KB Output is correct
13 Correct 165 ms 22084 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 71 ms 8196 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 5728 KB Output is correct
21 Correct 156 ms 22000 KB Output is correct
22 Correct 165 ms 22020 KB Output is correct
23 Correct 163 ms 22020 KB Output is correct
24 Correct 152 ms 22020 KB Output is correct
25 Correct 57 ms 8072 KB Output is correct
26 Correct 56 ms 8080 KB Output is correct
27 Correct 183 ms 22020 KB Output is correct
28 Correct 167 ms 22156 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 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 7 ms 1108 KB Output is correct
7 Correct 162 ms 21984 KB Output is correct
8 Correct 0 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 0 ms 212 KB Output is correct
12 Correct 7 ms 1184 KB Output is correct
13 Correct 165 ms 22084 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 71 ms 8196 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 5728 KB Output is correct
21 Correct 156 ms 22000 KB Output is correct
22 Correct 165 ms 22020 KB Output is correct
23 Correct 163 ms 22020 KB Output is correct
24 Correct 152 ms 22020 KB Output is correct
25 Correct 57 ms 8072 KB Output is correct
26 Correct 56 ms 8080 KB Output is correct
27 Correct 183 ms 22020 KB Output is correct
28 Correct 167 ms 22156 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 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -