답안 #838340

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
838340 2023-08-26T15:49:30 Z ma_moutahid 슈퍼트리 잇기 (IOI20_supertrees) C++17
21 / 100
175 ms 22092 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;
}
# 결과 실행 시간 메모리 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 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 163 ms 22024 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 163 ms 22024 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 224 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 6 ms 1108 KB Output is correct
13 Correct 154 ms 22036 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 68 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 39 ms 5708 KB Output is correct
21 Correct 155 ms 22092 KB Output is correct
22 Correct 154 ms 22092 KB Output is correct
23 Correct 161 ms 22080 KB Output is correct
24 Correct 154 ms 21964 KB Output is correct
25 Correct 65 ms 12160 KB Output is correct
26 Correct 64 ms 12168 KB Output is correct
27 Correct 164 ms 22092 KB Output is correct
28 Correct 157 ms 22012 KB Output is correct
# 결과 실행 시간 메모리 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 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 154 ms 21956 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 6 ms 1108 KB Output is correct
13 Correct 153 ms 22044 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 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 17 ms 3276 KB Answer gives possible 0 while actual possible 1
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 5768 KB Output is correct
5 Correct 157 ms 22064 KB Output is correct
6 Correct 172 ms 22092 KB Output is correct
7 Correct 175 ms 22024 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 16 ms 3276 KB Answer gives possible 0 while actual possible 1
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 163 ms 22024 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 224 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 6 ms 1108 KB Output is correct
13 Correct 154 ms 22036 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 68 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 39 ms 5708 KB Output is correct
21 Correct 155 ms 22092 KB Output is correct
22 Correct 154 ms 22092 KB Output is correct
23 Correct 161 ms 22080 KB Output is correct
24 Correct 154 ms 21964 KB Output is correct
25 Correct 65 ms 12160 KB Output is correct
26 Correct 64 ms 12168 KB Output is correct
27 Correct 164 ms 22092 KB Output is correct
28 Correct 157 ms 22012 KB Output is correct
29 Correct 1 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 Correct 0 ms 212 KB Output is correct
33 Correct 0 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 154 ms 21956 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 6 ms 1108 KB Output is correct
41 Correct 153 ms 22044 KB Output is correct
42 Correct 0 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 69 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 17 ms 3276 KB Answer gives possible 0 while actual possible 1
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 163 ms 22024 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 224 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 6 ms 1108 KB Output is correct
13 Correct 154 ms 22036 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 68 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 39 ms 5708 KB Output is correct
21 Correct 155 ms 22092 KB Output is correct
22 Correct 154 ms 22092 KB Output is correct
23 Correct 161 ms 22080 KB Output is correct
24 Correct 154 ms 21964 KB Output is correct
25 Correct 65 ms 12160 KB Output is correct
26 Correct 64 ms 12168 KB Output is correct
27 Correct 164 ms 22092 KB Output is correct
28 Correct 157 ms 22012 KB Output is correct
29 Correct 1 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 Correct 0 ms 212 KB Output is correct
33 Correct 0 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 154 ms 21956 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 6 ms 1108 KB Output is correct
41 Correct 153 ms 22044 KB Output is correct
42 Correct 0 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 69 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 17 ms 3276 KB Answer gives possible 0 while actual possible 1
50 Halted 0 ms 0 KB -