답안 #600468

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
600468 2022-07-20T22:14:57 Z UncoolAnon 슈퍼트리 잇기 (IOI20_supertrees) C++14
56 / 100
205 ms 22476 KB
#include <bits/stdc++.h> 
#include "supertrees.h"

using namespace std; 
const int inf=1e9; 
void merge(int i,int j,vector<int>& id,vector<vector<int>>& group){
	if(id[i]!=id[j]){
		int a=id[i],b=id[j]; 
		if(group[a].size()>group[b].size()) swap(a,b); 
		for(int&x:group[a]) group[b].push_back(x); 
		for(int&x:group[a]) id[x]=b; 
		group[a].clear(); 
	}	
	return ; 
}
int construct(vector<vector<int>> p){
	int n=p.size(); 
	vector<vector<int>> group(n),grp(n); 
	vector<int> id(n),rid(n); 
	for(int i=0;i<n;i++){
		id[i]=i; rid[i]=i; 
		group[i].push_back(i);
		grp[i].push_back(i);  
	}
	vector<vector<int>> answer(n,vector<int>(n,0)); 


	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i!=j&&group[id[i]].size()==1&&group[id[j]].size()==1&&p[i][j]==1){
				merge(i,j,rid,grp);
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int&x:grp[i])
			for(int&y:grp[i])
				if(p[x][y]!=1)
					return 0; 
		for(int&x:grp[i]) if(x!=i) answer[i][x]=answer[x][i]=1; 
	}
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++){
			if(rid[i]!=rid[j]&&rid[i]==i&&rid[j]==j){
				int zero=0,two=0; 
				for(int&x:grp[i])
					for(int&y:grp[j])
						zero+=(p[x][y]==0),two=(p[x][y]==2); 
				if(zero&&two) return 0; 
				if(two){
					merge(i,j,id,group); 
				}
			}
		}
	for(int i=0;i<n;i++)
		if(group[i].size()>1){
			for(int j=0;j<group[i].size();j++)
				answer[group[i][j]][group[i][(j+1)%group[i].size()]]=answer[group[i][(j+1)%group[i].size()]][group[i][j]]=1; 
		}
	build(answer); 
	return 1; 
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:57:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |    for(int j=0;j<group[i].size();j++)
      |                ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 1108 KB Output is correct
7 Correct 170 ms 22144 KB Output is correct
# 결과 실행 시간 메모리 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 1108 KB Output is correct
7 Correct 170 ms 22144 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 10 ms 1108 KB Output is correct
13 Correct 170 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 5 ms 724 KB Output is correct
17 Correct 87 ms 12160 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 43 ms 5764 KB Output is correct
21 Correct 172 ms 22100 KB Output is correct
22 Correct 192 ms 22080 KB Output is correct
23 Correct 177 ms 22096 KB Output is correct
24 Correct 167 ms 22088 KB Output is correct
25 Correct 80 ms 12236 KB Output is correct
26 Correct 72 ms 12240 KB Output is correct
27 Correct 175 ms 22148 KB Output is correct
28 Correct 182 ms 22136 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 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 56 ms 5964 KB Output is correct
5 Correct 182 ms 22356 KB Output is correct
6 Correct 175 ms 22324 KB Output is correct
7 Correct 180 ms 22384 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 44 ms 5940 KB Output is correct
10 Correct 174 ms 22440 KB Output is correct
11 Correct 170 ms 22476 KB Output is correct
12 Correct 192 ms 22384 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 45 ms 5964 KB Output is correct
17 Correct 177 ms 22392 KB Output is correct
18 Correct 205 ms 22340 KB Output is correct
19 Correct 176 ms 22424 KB Output is correct
20 Correct 170 ms 22312 KB Output is correct
# 결과 실행 시간 메모리 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 1108 KB Output is correct
7 Correct 170 ms 22144 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 10 ms 1108 KB Output is correct
13 Correct 170 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 5 ms 724 KB Output is correct
17 Correct 87 ms 12160 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 43 ms 5764 KB Output is correct
21 Correct 172 ms 22100 KB Output is correct
22 Correct 192 ms 22080 KB Output is correct
23 Correct 177 ms 22096 KB Output is correct
24 Correct 167 ms 22088 KB Output is correct
25 Correct 80 ms 12236 KB Output is correct
26 Correct 72 ms 12240 KB Output is correct
27 Correct 175 ms 22148 KB Output is correct
28 Correct 182 ms 22136 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 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1108 KB Output is correct
7 Correct 170 ms 22144 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 10 ms 1108 KB Output is correct
13 Correct 170 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 5 ms 724 KB Output is correct
17 Correct 87 ms 12160 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 43 ms 5764 KB Output is correct
21 Correct 172 ms 22100 KB Output is correct
22 Correct 192 ms 22080 KB Output is correct
23 Correct 177 ms 22096 KB Output is correct
24 Correct 167 ms 22088 KB Output is correct
25 Correct 80 ms 12236 KB Output is correct
26 Correct 72 ms 12240 KB Output is correct
27 Correct 175 ms 22148 KB Output is correct
28 Correct 182 ms 22136 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 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -