Submission #838336

# Submission time Handle Problem Language Result Execution time Memory
838336 2023-08-26T15:46:15 Z ma_moutahid Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
165 ms 22220 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 1 ms 232 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 161 ms 22220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 232 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 161 ms 22220 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 151 ms 21964 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 724 KB Output is correct
17 Correct 68 ms 12164 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 39 ms 5716 KB Output is correct
21 Correct 165 ms 22020 KB Output is correct
22 Correct 156 ms 22024 KB Output is correct
23 Correct 159 ms 22056 KB Output is correct
24 Correct 151 ms 21964 KB Output is correct
25 Correct 65 ms 12160 KB Output is correct
26 Correct 64 ms 12108 KB Output is correct
27 Correct 158 ms 22020 KB Output is correct
28 Correct 148 ms 22088 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 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 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 6 ms 1108 KB Output is correct
9 Correct 150 ms 22052 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 146 ms 22096 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 724 KB Output is correct
17 Correct 66 ms 12108 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Incorrect 16 ms 3284 KB Answer gives possible 0 while actual possible 1
22 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 0 ms 212 KB Output is correct
4 Correct 37 ms 5784 KB Output is correct
5 Correct 151 ms 22016 KB Output is correct
6 Correct 152 ms 22064 KB Output is correct
7 Correct 163 ms 22092 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Incorrect 15 ms 3284 KB Answer gives possible 0 while actual possible 1
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 232 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 161 ms 22220 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 151 ms 21964 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 724 KB Output is correct
17 Correct 68 ms 12164 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 39 ms 5716 KB Output is correct
21 Correct 165 ms 22020 KB Output is correct
22 Correct 156 ms 22024 KB Output is correct
23 Correct 159 ms 22056 KB Output is correct
24 Correct 151 ms 21964 KB Output is correct
25 Correct 65 ms 12160 KB Output is correct
26 Correct 64 ms 12108 KB Output is correct
27 Correct 158 ms 22020 KB Output is correct
28 Correct 148 ms 22088 KB Output is correct
29 Correct 1 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 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 6 ms 1108 KB Output is correct
37 Correct 150 ms 22052 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 7 ms 1108 KB Output is correct
41 Correct 146 ms 22096 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 66 ms 12108 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Incorrect 16 ms 3284 KB Answer gives possible 0 while actual possible 1
50 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 232 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 161 ms 22220 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 151 ms 21964 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 724 KB Output is correct
17 Correct 68 ms 12164 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 39 ms 5716 KB Output is correct
21 Correct 165 ms 22020 KB Output is correct
22 Correct 156 ms 22024 KB Output is correct
23 Correct 159 ms 22056 KB Output is correct
24 Correct 151 ms 21964 KB Output is correct
25 Correct 65 ms 12160 KB Output is correct
26 Correct 64 ms 12108 KB Output is correct
27 Correct 158 ms 22020 KB Output is correct
28 Correct 148 ms 22088 KB Output is correct
29 Correct 1 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 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 6 ms 1108 KB Output is correct
37 Correct 150 ms 22052 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 7 ms 1108 KB Output is correct
41 Correct 146 ms 22096 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 66 ms 12108 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Incorrect 16 ms 3284 KB Answer gives possible 0 while actual possible 1
50 Halted 0 ms 0 KB -