답안 #1039704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039704 2024-07-31T07:59:52 Z parsadox2 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
187 ms 28092 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 1e3 + 10;
int n;
vector <vector<int>> answer , p;
vector <int> all , all1;
bool flg , marked[N] , vis[N];

void Dfs(int v)
{
	marked[v] = true;
	all.push_back(v);
	for(int i = 0 ; i < n ; i++)  if(p[v][i] != 0 && !marked[i])
		Dfs(i);
}

bool check(vector <int> vec)
{
	bool res = true;
	for(auto u : vec)  for(auto v : vec)  if(p[u][v] != 1)
		res = false;
	for(int i = 1 ; i < vec.size() ; i++)
	{
		answer[vec[i]][vec[i - 1]] = 1;
		answer[vec[i - 1]][vec[i]] = 1;
	}
	return res;
}

void Dfs1(int v)
{
	vis[v] = true;
	all1.push_back(v);
	for(int i = 0 ; i < n ; i++)  if(p[v][i] == 1 && !vis[i])
		Dfs1(i);
}

void Solve()
{
	for(auto u : all)  for(auto v : all)  if(p[u][v] == 0 || p[u][v] == 3)
	{
		flg = false;
		return;
	}
	vector <vector<int>> cmp;
	for(auto u : all)  if(!vis[u])
	{
		all1.clear();
		Dfs1(u);
		if(!check(all1))
			flg = false;
		cmp.push_back(all1);
	}
	if(cmp.size() == 2)
	{
		flg = false;
		return;
	}
	if(cmp.size() == 1)
		return;
	for(int i = 1 ; i < cmp.size() ; i++)
	{
		answer[cmp[i].back()][cmp[i - 1].back()] = 1;
		answer[cmp[i - 1].back()][cmp[i].back()] = 1;
	}
	answer[cmp[cmp.size() - 1].back()][cmp[0].back()] = 1;
	answer[cmp[0].back()][cmp[cmp.size() - 1].back()] = 1;
}

int construct(vector<vector<int>> inp) {
	flg = true;
	p = inp;
	n = p.size();
	for (int i = 0; i < n; i++) {
		vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}
	for(int i = 0 ; i < n ; i++)  if(!marked[i])
	{
		all.clear();
		Dfs(i);
		Solve();
	}
	if(!flg)
		return 0;
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'bool check(std::vector<int>)':
supertrees.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for(int i = 1 ; i < vec.size() ; i++)
      |                  ~~^~~~~~~~~~~~
supertrees.cpp: In function 'void Solve()':
supertrees.cpp:64:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |  for(int i = 1 ; i < cmp.size() ; i++)
      |                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 1524 KB Output is correct
7 Correct 117 ms 27916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 1524 KB Output is correct
7 Correct 117 ms 27916 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1368 KB Output is correct
13 Correct 118 ms 27984 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 960 KB Output is correct
17 Correct 72 ms 18092 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 35 ms 7176 KB Output is correct
21 Correct 161 ms 28072 KB Output is correct
22 Correct 153 ms 28036 KB Output is correct
23 Correct 129 ms 27984 KB Output is correct
24 Correct 130 ms 27912 KB Output is correct
25 Correct 53 ms 18000 KB Output is correct
26 Correct 61 ms 18184 KB Output is correct
27 Correct 132 ms 27988 KB Output is correct
28 Correct 117 ms 27988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 436 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 6 ms 1372 KB Output is correct
9 Correct 136 ms 28080 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 122 ms 27988 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 1116 KB Output is correct
17 Correct 62 ms 18004 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 32 ms 7168 KB Output is correct
22 Correct 129 ms 28044 KB Output is correct
23 Correct 129 ms 27904 KB Output is correct
24 Correct 160 ms 28028 KB Output is correct
25 Correct 62 ms 18188 KB Output is correct
26 Correct 55 ms 18060 KB Output is correct
27 Correct 119 ms 27920 KB Output is correct
28 Correct 136 ms 28048 KB Output is correct
29 Correct 56 ms 18000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 31 ms 7228 KB Output is correct
5 Correct 123 ms 27988 KB Output is correct
6 Correct 131 ms 27988 KB Output is correct
7 Correct 127 ms 28092 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 30 ms 7296 KB Output is correct
10 Correct 124 ms 27908 KB Output is correct
11 Correct 120 ms 28080 KB Output is correct
12 Correct 127 ms 27988 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 440 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 37 ms 7244 KB Output is correct
17 Correct 130 ms 27916 KB Output is correct
18 Correct 187 ms 27916 KB Output is correct
19 Correct 123 ms 28044 KB Output is correct
20 Correct 122 ms 27984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 1524 KB Output is correct
7 Correct 117 ms 27916 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1368 KB Output is correct
13 Correct 118 ms 27984 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 960 KB Output is correct
17 Correct 72 ms 18092 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 35 ms 7176 KB Output is correct
21 Correct 161 ms 28072 KB Output is correct
22 Correct 153 ms 28036 KB Output is correct
23 Correct 129 ms 27984 KB Output is correct
24 Correct 130 ms 27912 KB Output is correct
25 Correct 53 ms 18000 KB Output is correct
26 Correct 61 ms 18184 KB Output is correct
27 Correct 132 ms 27988 KB Output is correct
28 Correct 117 ms 27988 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 436 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 600 KB Output is correct
36 Correct 6 ms 1372 KB Output is correct
37 Correct 136 ms 28080 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 1372 KB Output is correct
41 Correct 122 ms 27988 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 62 ms 18004 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 32 ms 7168 KB Output is correct
50 Correct 129 ms 28044 KB Output is correct
51 Correct 129 ms 27904 KB Output is correct
52 Correct 160 ms 28028 KB Output is correct
53 Correct 62 ms 18188 KB Output is correct
54 Correct 55 ms 18060 KB Output is correct
55 Correct 119 ms 27920 KB Output is correct
56 Correct 136 ms 28048 KB Output is correct
57 Correct 56 ms 18000 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 1116 KB Output is correct
61 Correct 64 ms 18044 KB Output is correct
62 Correct 0 ms 440 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 440 KB Output is correct
65 Correct 30 ms 7252 KB Output is correct
66 Correct 59 ms 18004 KB Output is correct
67 Correct 54 ms 18000 KB Output is correct
68 Correct 53 ms 18000 KB Output is correct
69 Correct 90 ms 18192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 1524 KB Output is correct
7 Correct 117 ms 27916 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1368 KB Output is correct
13 Correct 118 ms 27984 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 960 KB Output is correct
17 Correct 72 ms 18092 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 35 ms 7176 KB Output is correct
21 Correct 161 ms 28072 KB Output is correct
22 Correct 153 ms 28036 KB Output is correct
23 Correct 129 ms 27984 KB Output is correct
24 Correct 130 ms 27912 KB Output is correct
25 Correct 53 ms 18000 KB Output is correct
26 Correct 61 ms 18184 KB Output is correct
27 Correct 132 ms 27988 KB Output is correct
28 Correct 117 ms 27988 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 436 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 600 KB Output is correct
36 Correct 6 ms 1372 KB Output is correct
37 Correct 136 ms 28080 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 1372 KB Output is correct
41 Correct 122 ms 27988 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 62 ms 18004 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 32 ms 7168 KB Output is correct
50 Correct 129 ms 28044 KB Output is correct
51 Correct 129 ms 27904 KB Output is correct
52 Correct 160 ms 28028 KB Output is correct
53 Correct 62 ms 18188 KB Output is correct
54 Correct 55 ms 18060 KB Output is correct
55 Correct 119 ms 27920 KB Output is correct
56 Correct 136 ms 28048 KB Output is correct
57 Correct 56 ms 18000 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 31 ms 7228 KB Output is correct
62 Correct 123 ms 27988 KB Output is correct
63 Correct 131 ms 27988 KB Output is correct
64 Correct 127 ms 28092 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 30 ms 7296 KB Output is correct
67 Correct 124 ms 27908 KB Output is correct
68 Correct 120 ms 28080 KB Output is correct
69 Correct 127 ms 27988 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 440 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 37 ms 7244 KB Output is correct
74 Correct 130 ms 27916 KB Output is correct
75 Correct 187 ms 27916 KB Output is correct
76 Correct 123 ms 28044 KB Output is correct
77 Correct 122 ms 27984 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 3 ms 1116 KB Output is correct
81 Correct 64 ms 18044 KB Output is correct
82 Correct 0 ms 440 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 440 KB Output is correct
85 Correct 30 ms 7252 KB Output is correct
86 Correct 59 ms 18004 KB Output is correct
87 Correct 54 ms 18000 KB Output is correct
88 Correct 53 ms 18000 KB Output is correct
89 Correct 90 ms 18192 KB Output is correct
90 Correct 1 ms 344 KB Output is correct
91 Correct 1 ms 604 KB Output is correct
92 Correct 3 ms 1116 KB Output is correct
93 Correct 57 ms 18000 KB Output is correct
94 Correct 1 ms 348 KB Output is correct
95 Correct 0 ms 344 KB Output is correct
96 Correct 1 ms 348 KB Output is correct
97 Correct 13 ms 4880 KB Output is correct
98 Correct 55 ms 18004 KB Output is correct
99 Correct 55 ms 18004 KB Output is correct
100 Correct 61 ms 18128 KB Output is correct
101 Correct 71 ms 18188 KB Output is correct
102 Correct 51 ms 18000 KB Output is correct
103 Correct 52 ms 18004 KB Output is correct
104 Correct 96 ms 18000 KB Output is correct
105 Correct 68 ms 18236 KB Output is correct