답안 #1013205

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1013205 2024-07-03T09:57:24 Z Luvidi 슈퍼트리 잇기 (IOI20_supertrees) C++17
40 / 100
170 ms 24400 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

int par[1000],sz[1000];
vector<vector<int>> ans;

int rep(int x){
	while(x!=par[x])x=par[x];
	return x;
}

void join(int x,int y){
	x=rep(x);y=rep(y);
	if(x==y)return;
	if(sz[x]>sz[y])swap(x,y);
	par[x]=y;
	sz[y]+=sz[x];
}

void edge(int x,int y){
	ans[x][y]=1;
	ans[y][x]=1;
}

int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	for(int i=0;i<n;i++){
		par[i]=i;
		sz[i]=1;
	}
	for (int i=0;i<n;i++){
		vector<int> row;
		row.resize(n);
		ans.push_back(row);
	}
	bool s2=1,s3=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++){
			if(p[i][j]){
				s2&=p[i][j]==1;
				s3&=p[i][j]==2;
				join(i,j);
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++){
			if(p[i][j]==0){
				if(rep(i)==rep(j))return 0;
			}else{
				if(rep(i)!=rep(j))return 0;
			}
		}
	}
	vector<int> v[n];
	for(int i=0;i<n;i++)v[rep(i)].push_back(i);
	for(int i=0;i<n;i++)if(v[i].size()>1){
		if(s2){
			for(int j=0;j+1<v[i].size();j++){
				edge(v[i][j],v[i][j+1]);
			}
		}else{
			if(v[i].size()==2)return 0;
			for(int j=0;j+1<v[i].size();j++){
				edge(v[i][j],v[i][j+1]);
			}
			edge(v[i][0],v[i].back());
		}
	}
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:60:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |    for(int j=0;j+1<v[i].size();j++){
      |                ~~~^~~~~~~~~~~~
supertrees.cpp:65:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |    for(int j=0;j+1<v[i].size();j++){
      |                ~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 117 ms 23932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 117 ms 23932 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 1192 KB Output is correct
13 Correct 152 ms 24144 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 69 ms 14096 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 54 ms 6228 KB Output is correct
21 Correct 159 ms 24076 KB Output is correct
22 Correct 170 ms 24180 KB Output is correct
23 Correct 126 ms 23948 KB Output is correct
24 Correct 127 ms 24068 KB Output is correct
25 Correct 59 ms 14216 KB Output is correct
26 Correct 55 ms 14204 KB Output is correct
27 Correct 125 ms 24148 KB Output is correct
28 Correct 113 ms 24144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 436 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 440 KB Output is correct
8 Correct 5 ms 1372 KB Output is correct
9 Correct 127 ms 23980 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 5 ms 1192 KB Output is correct
13 Correct 124 ms 24144 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 936 KB Output is correct
17 Correct 70 ms 14164 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 29 ms 6236 KB Output is correct
22 Correct 117 ms 24148 KB Output is correct
23 Correct 122 ms 24148 KB Output is correct
24 Correct 121 ms 24072 KB Output is correct
25 Correct 54 ms 14164 KB Output is correct
26 Correct 51 ms 14096 KB Output is correct
27 Correct 134 ms 24400 KB Output is correct
28 Correct 129 ms 24080 KB Output is correct
29 Correct 65 ms 14220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 504 KB Output is correct
4 Correct 29 ms 6368 KB Output is correct
5 Correct 116 ms 24148 KB Output is correct
6 Correct 119 ms 24076 KB Output is correct
7 Correct 128 ms 23936 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 29 ms 6208 KB Output is correct
10 Correct 116 ms 24076 KB Output is correct
11 Correct 114 ms 24148 KB Output is correct
12 Correct 123 ms 24056 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Incorrect 1 ms 348 KB Too many ways to get from 4 to 8, should be 1 found no less than 2
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 117 ms 23932 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 1192 KB Output is correct
13 Correct 152 ms 24144 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 69 ms 14096 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 54 ms 6228 KB Output is correct
21 Correct 159 ms 24076 KB Output is correct
22 Correct 170 ms 24180 KB Output is correct
23 Correct 126 ms 23948 KB Output is correct
24 Correct 127 ms 24068 KB Output is correct
25 Correct 59 ms 14216 KB Output is correct
26 Correct 55 ms 14204 KB Output is correct
27 Correct 125 ms 24148 KB Output is correct
28 Correct 113 ms 24144 KB Output is correct
29 Correct 0 ms 436 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 440 KB Output is correct
36 Correct 5 ms 1372 KB Output is correct
37 Correct 127 ms 23980 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 5 ms 1192 KB Output is correct
41 Correct 124 ms 24144 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 4 ms 936 KB Output is correct
45 Correct 70 ms 14164 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 29 ms 6236 KB Output is correct
50 Correct 117 ms 24148 KB Output is correct
51 Correct 122 ms 24148 KB Output is correct
52 Correct 121 ms 24072 KB Output is correct
53 Correct 54 ms 14164 KB Output is correct
54 Correct 51 ms 14096 KB Output is correct
55 Correct 134 ms 24400 KB Output is correct
56 Correct 129 ms 24080 KB Output is correct
57 Correct 65 ms 14220 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 3 ms 936 KB Output is correct
61 Correct 56 ms 14220 KB Output is correct
62 Correct 1 ms 344 KB Output is correct
63 Incorrect 0 ms 348 KB Too many ways to get from 0 to 9, should be 1 found no less than 2
64 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 117 ms 23932 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 1192 KB Output is correct
13 Correct 152 ms 24144 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 69 ms 14096 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 54 ms 6228 KB Output is correct
21 Correct 159 ms 24076 KB Output is correct
22 Correct 170 ms 24180 KB Output is correct
23 Correct 126 ms 23948 KB Output is correct
24 Correct 127 ms 24068 KB Output is correct
25 Correct 59 ms 14216 KB Output is correct
26 Correct 55 ms 14204 KB Output is correct
27 Correct 125 ms 24148 KB Output is correct
28 Correct 113 ms 24144 KB Output is correct
29 Correct 0 ms 436 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 440 KB Output is correct
36 Correct 5 ms 1372 KB Output is correct
37 Correct 127 ms 23980 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 5 ms 1192 KB Output is correct
41 Correct 124 ms 24144 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 4 ms 936 KB Output is correct
45 Correct 70 ms 14164 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 29 ms 6236 KB Output is correct
50 Correct 117 ms 24148 KB Output is correct
51 Correct 122 ms 24148 KB Output is correct
52 Correct 121 ms 24072 KB Output is correct
53 Correct 54 ms 14164 KB Output is correct
54 Correct 51 ms 14096 KB Output is correct
55 Correct 134 ms 24400 KB Output is correct
56 Correct 129 ms 24080 KB Output is correct
57 Correct 65 ms 14220 KB Output is correct
58 Correct 1 ms 344 KB Output is correct
59 Correct 1 ms 344 KB Output is correct
60 Correct 0 ms 504 KB Output is correct
61 Correct 29 ms 6368 KB Output is correct
62 Correct 116 ms 24148 KB Output is correct
63 Correct 119 ms 24076 KB Output is correct
64 Correct 128 ms 23936 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 29 ms 6208 KB Output is correct
67 Correct 116 ms 24076 KB Output is correct
68 Correct 114 ms 24148 KB Output is correct
69 Correct 123 ms 24056 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Incorrect 1 ms 348 KB Too many ways to get from 4 to 8, should be 1 found no less than 2
72 Halted 0 ms 0 KB -