답안 #827015

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
827015 2023-08-16T08:01:00 Z tomruk 슈퍼트리 잇기 (IOI20_supertrees) C++17
46 / 100
173 ms 23192 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int>> answer(n,(vector<int>(n,0)));
	vector<bool> used(n,0);
	function<void(int)> dfs = [&](int v)->void{
		used[v] = 1;
		for(int i = 0;i<n;i++){
			if(!used[i] && p[v][i] == 1){
				dfs(i);
				answer[v][i] = 1;
				answer[i][v] = 1;
			}
		}
	};
	for(int i = 0;i<n;i++){
		if(used[i])continue;
		int now = i;
		vector<int> tmp;
		int num = -1;
		set<int> s;
		for(int j = 0;j<n;j++){
			if(p[now][j] >= 2){
				if(num == -1)
					num = p[now][j];
				if(num != p[now][j])
					return 0;
				s.insert(j);
			}
		}
		while(s.size()){
			tmp.push_back(now);
			used[now] = 1;
			vector<int> del;
			for(auto u:s){
				if(p[now][u] < 2){
					del.push_back(u);
				}
			}
			for(auto u:del)
				s.erase(u);
			if(s.empty())
				break;
			now = *s.begin();
		}
		if(tmp.empty())
			continue;
		if(tmp.size() < 3){
			return 0;
		}
		for(int i = 0;i<tmp.size();i++){
			answer[tmp[i]][tmp[(i + 1)%tmp.size()]] = 1;
			answer[tmp[(i + 1)%tmp.size()]][tmp[i]] = 1;
		}
		if(num == 3){
			if(tmp.size() < 4)
				return 0;
			answer[tmp[i]][tmp[(i + 2)%tmp.size()]] = 1;
			answer[tmp[(i + 2)%tmp.size()]][tmp[i]] = 1;
		}
		for(auto u:tmp){
			dfs(u);
		}
	}
	for(int i = 0;i<n;i++){
		// cout << used[i] << endl;
		if(!used[i])
			dfs(i);
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:53:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for(int i = 0;i<tmp.size();i++){
      |                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 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 0 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 150 ms 22032 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 0 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 150 ms 22032 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 151 ms 22028 KB Output is correct
14 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
15 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 10 ms 1168 KB Output is correct
9 Correct 146 ms 21944 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 152 ms 22052 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Incorrect 10 ms 1256 KB Answer gives possible 1 while actual possible 0
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 48 ms 5748 KB Output is correct
5 Correct 173 ms 22052 KB Output is correct
6 Correct 152 ms 22008 KB Output is correct
7 Correct 156 ms 21992 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 37 ms 5768 KB Output is correct
10 Correct 156 ms 21984 KB Output is correct
11 Correct 167 ms 22052 KB Output is correct
12 Correct 157 ms 22064 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 47 ms 5984 KB Output is correct
17 Correct 152 ms 22808 KB Output is correct
18 Correct 154 ms 22980 KB Output is correct
19 Correct 158 ms 23172 KB Output is correct
20 Correct 158 ms 23192 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 0 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 150 ms 22032 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 151 ms 22028 KB Output is correct
14 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
15 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 0 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 150 ms 22032 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 151 ms 22028 KB Output is correct
14 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -