Submission #838324

# Submission time Handle Problem Language Result Execution time Memory
838324 2023-08-26T15:20:46 Z ma_moutahid Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
164 ms 24060 KB
#include "supertrees.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vii vector<vi>
vi d;
vi h;

int parent(int x){
	if(d[x]==x)return x;
	return d[x]=parent(d[x]);
}

void connect(int a, int b){
	a=parent(a);
	b=parent(b);
	if(a==b)return;

	if(h[a]<h[b])swap(a,b);
	d[b]=a;
	if(h[a]==h[b])h[a]++;
}



int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	vii answer(n,vi(n));
	d.resize(n);h.resize(n,1);for(int i=0;i<n;i++)d[i]=i;
	for (int i = 0; i < n; i++) {
		for(int j=i+1;j<n;j++)if(p[i][j])connect(i,j);
	}
	vi bp(n,-1);
	vector<set<int>>bs;
	for(int i=0;i<n;i++){
		int pr=parent(i);
		if(h[pr]<=1)continue;
		if(bp[pr]==-1 ){
			bp[pr]=bs.size();
			bs.resize(bs.size()+1);
			
		}
		bs[bp[pr]].insert(i);
	}

	for( auto &s:bs){
		vector<set<int>>sets;
		vi pr(n,-1);
		for(auto itr1=s.begin();next(itr1)!=s.end();itr1++){
			int a=*itr1;
			if(pr[a]==-1){
				pr[a]=sets.size();
				sets.resize(sets.size()+1);
				sets[pr[a]].insert(a);
			}
			for( auto itr2=next(itr1);itr2!=s.end();itr2++){
				int b=*itr2;
				if(p[a][b]==0)return 0;
				if(p[a][b]==1){
					pr[b]=pr[a];
					sets[pr[a]].insert(b);
					
				}
			}
		}
		vi v;
		for( auto &st:sets){
			v.push_back(*st.begin());
			for(auto itr=st.begin();next(itr)!=st.end();itr++){
				answer[(*itr)][(*next(itr))]=1;
				answer[*next(itr)][*itr]=1;
				for(auto itr2=next(itr);itr2!=st.end();itr2++){
					if(p[*itr][*itr2]>1)return 0;
				}
			}
		}
		int sz=v.size();
	
		if(sz<=1)continue;
		if(sz==2)return 0;
		int num=p[v[0]][v[sz-1]];
		answer[v[0]][v[sz-1]]=1;
		answer[v[sz-1]][v[0]]=1;
		for(int i=0;i<sz-1;i++){
			if(p[i][i+1]!=num)return 0;
			answer[i][i+1]=1;
			answer[i+1][i]=1;
		}
		if(num ==3 ){
			answer[0][2]=1;
			answer[2][0]=1;
		}
		
	}



	build(answer);
	return 1;
}
# 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 0 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 164 ms 23948 KB Output is correct
# 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 0 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 164 ms 23948 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 154 ms 23980 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 792 KB Output is correct
17 Correct 79 ms 14072 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 39 ms 6256 KB Output is correct
21 Correct 155 ms 24024 KB Output is correct
22 Correct 154 ms 24060 KB Output is correct
23 Correct 164 ms 23992 KB Output is correct
24 Correct 153 ms 23972 KB Output is correct
25 Correct 66 ms 14072 KB Output is correct
26 Correct 64 ms 14068 KB Output is correct
27 Correct 163 ms 24036 KB Output is correct
28 Correct 157 ms 24012 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 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 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 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 0 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 164 ms 23948 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 154 ms 23980 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 792 KB Output is correct
17 Correct 79 ms 14072 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 39 ms 6256 KB Output is correct
21 Correct 155 ms 24024 KB Output is correct
22 Correct 154 ms 24060 KB Output is correct
23 Correct 164 ms 23992 KB Output is correct
24 Correct 153 ms 23972 KB Output is correct
25 Correct 66 ms 14072 KB Output is correct
26 Correct 64 ms 14068 KB Output is correct
27 Correct 163 ms 24036 KB Output is correct
28 Correct 157 ms 24012 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 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 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 0 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 164 ms 23948 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 154 ms 23980 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 792 KB Output is correct
17 Correct 79 ms 14072 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 39 ms 6256 KB Output is correct
21 Correct 155 ms 24024 KB Output is correct
22 Correct 154 ms 24060 KB Output is correct
23 Correct 164 ms 23992 KB Output is correct
24 Correct 153 ms 23972 KB Output is correct
25 Correct 66 ms 14072 KB Output is correct
26 Correct 64 ms 14068 KB Output is correct
27 Correct 163 ms 24036 KB Output is correct
28 Correct 157 ms 24012 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 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -