답안 #411114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
411114 2021-05-24T11:43:34 Z eagle30 슈퍼트리 잇기 (IOI20_supertrees) C++17
40 / 100
246 ms 30216 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
int visited[2000], hi[1000000];
vector<vector<int> > adjlist;
int coun=1;
void dfs(int s){
	visited[s]=coun;
	for(int i=0; i<adjlist[s].size(); i++){
		int v=adjlist[s][i];
		if(visited[v]==0)
			dfs(v);
	}
}
int construct(vector<vector<int> > p) {
	int n = p.size();
	adjlist.assign(n+1, vector<int>());
	bool is=false;
	set<int> si;
	for(int i=0; i<n; i++){
		bool zxcv=true;
		for(int j=0; j<n; j++){
			if(p[i][j] && i!=j){
				si.insert(p[i][j]);
				if(p[i][j]==1)
					zxcv=false;
				adjlist[i].push_back(j);
				adjlist[j].push_back(i);
			}
			if(p[i][j]==2)
				is=true;
		}
		if(zxcv)
			hi[i]=1;
	}
	for(int i=0; i<n; i++){
		if(visited[i]==0){
			dfs(i);
			coun++;
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(visited[i]==visited[j] && p[i][j]==0)
				return 0;
		}
	}
	vector<vector<int> > answer;
	answer.assign(n, vector<int>());
	for(int i=0; i<n; i++)
		answer[i].assign(n, 0);
	map<int, vector<int> > mp;
	for(int i=0; i<n; i++)
		mp[visited[i]].push_back(i);
	if(si.size()<=1){
		for(auto x:mp){
			for(int i=1; i<x.second.size(); i++){
				answer[x.second[i-1]][x.second[i]]=1;
				answer[x.second[i]][x.second[i-1]]=1;
			}
			if(is){
				if(x.second.size()==1)
					continue;
				if(x.second.size()==2)
					return 0;
				answer[x.second[0]][x.second[x.second.size()-1]]=1;
				answer[x.second[x.second.size()-1]][x.second[0]]=1;
			}
		}
	}
	else{
		for(auto x:mp){
			vector<int> vi;
			int asdf, hi1=x.second.size();
			for(int i=0; i<hi1; i++){
				if(hi[x.second[i]])
					vi.push_back(x.second[i]);
			}
			asdf=vi.size();
			for(int i=0; i<hi1; i++)
				if(!hi[x.second[i]])
					vi.push_back(x.second[i]);
			hi1=vi.size();
			for(int i=1; i<hi1; i++){
				answer[vi[i-1]][vi[i]]=1;
				answer[vi[i]][vi[i-1]]=1;
			}
			if(asdf>1){
				answer[vi[0]][vi[asdf-1]]=1;
				answer[vi[asdf-1]][vi[0]]=1;
			}
		}
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'void dfs(int)':
supertrees.cpp:9:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |  for(int i=0; i<adjlist[s].size(); i++){
      |               ~^~~~~~~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:57:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |    for(int i=1; i<x.second.size(); i++){
      |                 ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1612 KB Output is correct
7 Correct 244 ms 30172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1612 KB Output is correct
7 Correct 244 ms 30172 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1216 KB Output is correct
13 Correct 225 ms 22152 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 113 ms 13964 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 57 ms 5900 KB Output is correct
21 Correct 231 ms 23128 KB Output is correct
22 Correct 224 ms 22228 KB Output is correct
23 Correct 239 ms 26260 KB Output is correct
24 Correct 219 ms 22084 KB Output is correct
25 Correct 98 ms 9240 KB Output is correct
26 Correct 91 ms 8160 KB Output is correct
27 Correct 239 ms 28188 KB Output is correct
28 Correct 232 ms 22160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 10 ms 1228 KB Output is correct
9 Correct 220 ms 22104 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1612 KB Output is correct
13 Correct 235 ms 30216 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 116 ms 13832 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 57 ms 5836 KB Output is correct
22 Correct 223 ms 23076 KB Output is correct
23 Correct 218 ms 22084 KB Output is correct
24 Correct 241 ms 28312 KB Output is correct
25 Correct 99 ms 12228 KB Output is correct
26 Correct 106 ms 9228 KB Output is correct
27 Correct 226 ms 22160 KB Output is correct
28 Correct 246 ms 26180 KB Output is correct
29 Correct 99 ms 12296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 64 ms 5788 KB Output is correct
5 Correct 238 ms 23200 KB Output is correct
6 Correct 216 ms 22084 KB Output is correct
7 Correct 238 ms 26156 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 56 ms 5828 KB Output is correct
10 Correct 233 ms 23112 KB Output is correct
11 Correct 221 ms 22152 KB Output is correct
12 Correct 240 ms 28348 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Incorrect 1 ms 204 KB Too few ways to get from 0 to 1, should be 2 found 1
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1612 KB Output is correct
7 Correct 244 ms 30172 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1216 KB Output is correct
13 Correct 225 ms 22152 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 113 ms 13964 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 57 ms 5900 KB Output is correct
21 Correct 231 ms 23128 KB Output is correct
22 Correct 224 ms 22228 KB Output is correct
23 Correct 239 ms 26260 KB Output is correct
24 Correct 219 ms 22084 KB Output is correct
25 Correct 98 ms 9240 KB Output is correct
26 Correct 91 ms 8160 KB Output is correct
27 Correct 239 ms 28188 KB Output is correct
28 Correct 232 ms 22160 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 10 ms 1228 KB Output is correct
37 Correct 220 ms 22104 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 10 ms 1612 KB Output is correct
41 Correct 235 ms 30216 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 5 ms 844 KB Output is correct
45 Correct 116 ms 13832 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 57 ms 5836 KB Output is correct
50 Correct 223 ms 23076 KB Output is correct
51 Correct 218 ms 22084 KB Output is correct
52 Correct 241 ms 28312 KB Output is correct
53 Correct 99 ms 12228 KB Output is correct
54 Correct 106 ms 9228 KB Output is correct
55 Correct 226 ms 22160 KB Output is correct
56 Correct 246 ms 26180 KB Output is correct
57 Correct 99 ms 12296 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 6 ms 1032 KB Output is correct
61 Correct 137 ms 16964 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Incorrect 56 ms 5768 KB Too few ways to get from 1 to 11, should be 2 found 1
66 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1612 KB Output is correct
7 Correct 244 ms 30172 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1216 KB Output is correct
13 Correct 225 ms 22152 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 113 ms 13964 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 57 ms 5900 KB Output is correct
21 Correct 231 ms 23128 KB Output is correct
22 Correct 224 ms 22228 KB Output is correct
23 Correct 239 ms 26260 KB Output is correct
24 Correct 219 ms 22084 KB Output is correct
25 Correct 98 ms 9240 KB Output is correct
26 Correct 91 ms 8160 KB Output is correct
27 Correct 239 ms 28188 KB Output is correct
28 Correct 232 ms 22160 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 10 ms 1228 KB Output is correct
37 Correct 220 ms 22104 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 10 ms 1612 KB Output is correct
41 Correct 235 ms 30216 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 5 ms 844 KB Output is correct
45 Correct 116 ms 13832 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 57 ms 5836 KB Output is correct
50 Correct 223 ms 23076 KB Output is correct
51 Correct 218 ms 22084 KB Output is correct
52 Correct 241 ms 28312 KB Output is correct
53 Correct 99 ms 12228 KB Output is correct
54 Correct 106 ms 9228 KB Output is correct
55 Correct 226 ms 22160 KB Output is correct
56 Correct 246 ms 26180 KB Output is correct
57 Correct 99 ms 12296 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 64 ms 5788 KB Output is correct
62 Correct 238 ms 23200 KB Output is correct
63 Correct 216 ms 22084 KB Output is correct
64 Correct 238 ms 26156 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 56 ms 5828 KB Output is correct
67 Correct 233 ms 23112 KB Output is correct
68 Correct 221 ms 22152 KB Output is correct
69 Correct 240 ms 28348 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Incorrect 1 ms 204 KB Too few ways to get from 0 to 1, should be 2 found 1
73 Halted 0 ms 0 KB -