Submission #838337

# Submission time Handle Problem Language Result Execution time Memory
838337 2023-08-26T15:47:09 Z ma_moutahid Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
194 ms 22148 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();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=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 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 212 KB Output is correct
6 Correct 7 ms 1144 KB Output is correct
7 Correct 169 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 1 ms 212 KB Output is correct
6 Correct 7 ms 1144 KB Output is correct
7 Correct 169 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 1108 KB Output is correct
13 Correct 180 ms 22024 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 69 ms 12164 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 41 ms 5728 KB Output is correct
21 Correct 166 ms 22028 KB Output is correct
22 Correct 167 ms 22116 KB Output is correct
23 Correct 164 ms 22148 KB Output is correct
24 Correct 158 ms 22016 KB Output is correct
25 Correct 65 ms 12108 KB Output is correct
26 Correct 64 ms 12164 KB Output is correct
27 Correct 162 ms 22016 KB Output is correct
28 Correct 154 ms 21960 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 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 Correct 39 ms 5732 KB Output is correct
5 Correct 155 ms 22000 KB Output is correct
6 Correct 173 ms 22020 KB Output is correct
7 Correct 194 ms 22020 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 17 ms 3212 KB Answer gives possible 0 while actual possible 1
10 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 1 ms 212 KB Output is correct
6 Correct 7 ms 1144 KB Output is correct
7 Correct 169 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 1108 KB Output is correct
13 Correct 180 ms 22024 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 69 ms 12164 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 41 ms 5728 KB Output is correct
21 Correct 166 ms 22028 KB Output is correct
22 Correct 167 ms 22116 KB Output is correct
23 Correct 164 ms 22148 KB Output is correct
24 Correct 158 ms 22016 KB Output is correct
25 Correct 65 ms 12108 KB Output is correct
26 Correct 64 ms 12164 KB Output is correct
27 Correct 162 ms 22016 KB Output is correct
28 Correct 154 ms 21960 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 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 212 KB Output is correct
6 Correct 7 ms 1144 KB Output is correct
7 Correct 169 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 1108 KB Output is correct
13 Correct 180 ms 22024 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 69 ms 12164 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 41 ms 5728 KB Output is correct
21 Correct 166 ms 22028 KB Output is correct
22 Correct 167 ms 22116 KB Output is correct
23 Correct 164 ms 22148 KB Output is correct
24 Correct 158 ms 22016 KB Output is correct
25 Correct 65 ms 12108 KB Output is correct
26 Correct 64 ms 12164 KB Output is correct
27 Correct 162 ms 22016 KB Output is correct
28 Correct 154 ms 21960 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 -