답안 #497140

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
497140 2021-12-22T14:41:26 Z Hanksburger 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
234 ms 24008 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > grp, subgrp, ans;
bool visited[1005];
vector<int> tmp;
queue<int> Q;
int construct(vector<vector<int> > P)
{
	int N=P.size();
	for (int i=0; i<N; i++)
		for (int j=i+1; j<N; j++)
			if (P[i][j]==3)
				return 0;
	for (int i=0; i<N; i++)
	{
		tmp.clear();
		for (int j=0; j<N; j++)
			tmp.push_back(0);
		ans.push_back(tmp);
	}
	for (int i=0; i<N; i++)
	{
		if (visited[i])
			continue;
		tmp.clear();
		tmp.push_back(i);
		Q.push(i);
		visited[i]=1;
		while (!Q.empty())
		{
			int u=Q.front();
			Q.pop();
			for (int j=0; j<N; j++)
			{
				if (P[u][j] && !visited[j])
				{
					tmp.push_back(j);
					Q.push(j);
					visited[j]=1;
				}
			}
		}
		grp.push_back(tmp);
	}
	for (int i=0; i<grp.size(); i++)
	{
		for (int j=0; j<grp[i].size(); j++)
		{
			int u=grp[i][j];
			for (int k=j+1; k<grp[i].size(); k++)
				if (!P[u][grp[i][k]])
					return 0;
		}
	}
	for (int i=0; i<N; i++)
		visited[i]=0;
	for (int i=0; i<grp.size(); i++)
	{
		subgrp.clear();
		for (int j=0; j<grp[i].size(); j++)
		{
			int x=grp[i][j];
			if (visited[x])
				continue;
			tmp.clear();
			tmp.push_back(x);
			Q.push(x);
			visited[x]=1;
			while (!Q.empty())
			{
				int u=Q.front();
				Q.pop();
				for (int k=0; k<N; k++)
				{
					if (P[u][k]==1 && !visited[k])
					{
						tmp.push_back(k);
						Q.push(k);
						visited[k]=1;
					}
				}
			}
			subgrp.push_back(tmp);
		}
		if (subgrp.size()==2)
			return 0;
		for (int j=0; j<subgrp.size(); j++)
		{
			for (int k=0; k<subgrp[j].size(); k++)
			{
				int u=subgrp[j][k];
				for (int l=k+1; l<subgrp[j].size(); l++)
					if (P[u][subgrp[j][l]]==2)
						return 0;
			}
		}
		for (int j=0; j<subgrp.size(); j++)
		{
			for (int k=1; k<subgrp[j].size(); k++)
			{
				int u=subgrp[j][k-1], v=subgrp[j][k];
				ans[u][v]=ans[v][u]=1;
			}
		}
		if (subgrp.size()>=3)
		{
			for (int j=1; j<subgrp.size(); j++)
			{
				int u=subgrp[j-1][0], v=subgrp[j][0];
				ans[u][v]=ans[v][u]=1;
			}
			int u=subgrp[0][0], v=subgrp[subgrp.size()-1][0];
			ans[u][v]=ans[v][u]=1;
		}
	}
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:46:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |  for (int i=0; i<grp.size(); i++)
      |                ~^~~~~~~~~~~
supertrees.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   for (int j=0; j<grp[i].size(); j++)
      |                 ~^~~~~~~~~~~~~~
supertrees.cpp:51:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |    for (int k=j+1; k<grp[i].size(); k++)
      |                    ~^~~~~~~~~~~~~~
supertrees.cpp:58:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for (int i=0; i<grp.size(); i++)
      |                ~^~~~~~~~~~~
supertrees.cpp:61:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   for (int j=0; j<grp[i].size(); j++)
      |                 ~^~~~~~~~~~~~~~
supertrees.cpp:88:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |   for (int j=0; j<subgrp.size(); j++)
      |                 ~^~~~~~~~~~~~~~
supertrees.cpp:90:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |    for (int k=0; k<subgrp[j].size(); k++)
      |                  ~^~~~~~~~~~~~~~~~~
supertrees.cpp:93:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |     for (int l=k+1; l<subgrp[j].size(); l++)
      |                     ~^~~~~~~~~~~~~~~~~
supertrees.cpp:98:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |   for (int j=0; j<subgrp.size(); j++)
      |                 ~^~~~~~~~~~~~~~
supertrees.cpp:100:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |    for (int k=1; k<subgrp[j].size(); k++)
      |                  ~^~~~~~~~~~~~~~~~~
supertrees.cpp:108:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |    for (int j=1; j<subgrp.size(); j++)
      |                  ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 272 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 10 ms 1204 KB Output is correct
7 Correct 170 ms 22668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 272 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 10 ms 1204 KB Output is correct
7 Correct 170 ms 22668 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 0 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 8 ms 1180 KB Output is correct
13 Correct 234 ms 22448 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 4 ms 844 KB Output is correct
17 Correct 92 ms 12580 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 45 ms 6136 KB Output is correct
21 Correct 179 ms 22448 KB Output is correct
22 Correct 175 ms 22628 KB Output is correct
23 Correct 200 ms 22480 KB Output is correct
24 Correct 196 ms 22436 KB Output is correct
25 Correct 74 ms 12524 KB Output is correct
26 Correct 71 ms 12536 KB Output is correct
27 Correct 183 ms 22460 KB Output is correct
28 Correct 215 ms 22512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 292 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 7 ms 1172 KB Output is correct
9 Correct 192 ms 22564 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 8 ms 1204 KB Output is correct
13 Correct 187 ms 22536 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 7 ms 820 KB Output is correct
17 Correct 101 ms 12704 KB Output is correct
18 Correct 1 ms 292 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 44 ms 6144 KB Output is correct
22 Correct 183 ms 22724 KB Output is correct
23 Correct 173 ms 22604 KB Output is correct
24 Correct 175 ms 22532 KB Output is correct
25 Correct 85 ms 12808 KB Output is correct
26 Correct 76 ms 12724 KB Output is correct
27 Correct 173 ms 22520 KB Output is correct
28 Correct 190 ms 22568 KB Output is correct
29 Correct 72 ms 12712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 52 ms 6096 KB Output is correct
5 Correct 192 ms 22468 KB Output is correct
6 Correct 207 ms 22552 KB Output is correct
7 Correct 182 ms 22468 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 47 ms 6092 KB Output is correct
10 Correct 174 ms 22556 KB Output is correct
11 Correct 186 ms 22520 KB Output is correct
12 Correct 197 ms 22728 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 51 ms 6188 KB Output is correct
17 Correct 189 ms 24008 KB Output is correct
18 Correct 177 ms 24008 KB Output is correct
19 Correct 178 ms 24004 KB Output is correct
20 Correct 175 ms 23968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 272 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 10 ms 1204 KB Output is correct
7 Correct 170 ms 22668 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 0 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 8 ms 1180 KB Output is correct
13 Correct 234 ms 22448 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 4 ms 844 KB Output is correct
17 Correct 92 ms 12580 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 45 ms 6136 KB Output is correct
21 Correct 179 ms 22448 KB Output is correct
22 Correct 175 ms 22628 KB Output is correct
23 Correct 200 ms 22480 KB Output is correct
24 Correct 196 ms 22436 KB Output is correct
25 Correct 74 ms 12524 KB Output is correct
26 Correct 71 ms 12536 KB Output is correct
27 Correct 183 ms 22460 KB Output is correct
28 Correct 215 ms 22512 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 1 ms 296 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 0 ms 292 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 7 ms 1172 KB Output is correct
37 Correct 192 ms 22564 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 8 ms 1204 KB Output is correct
41 Correct 187 ms 22536 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 7 ms 820 KB Output is correct
45 Correct 101 ms 12704 KB Output is correct
46 Correct 1 ms 292 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 44 ms 6144 KB Output is correct
50 Correct 183 ms 22724 KB Output is correct
51 Correct 173 ms 22604 KB Output is correct
52 Correct 175 ms 22532 KB Output is correct
53 Correct 85 ms 12808 KB Output is correct
54 Correct 76 ms 12724 KB Output is correct
55 Correct 173 ms 22520 KB Output is correct
56 Correct 190 ms 22568 KB Output is correct
57 Correct 72 ms 12712 KB Output is correct
58 Correct 1 ms 296 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 4 ms 844 KB Output is correct
61 Correct 96 ms 12716 KB Output is correct
62 Correct 1 ms 300 KB Output is correct
63 Correct 0 ms 204 KB Output is correct
64 Correct 0 ms 204 KB Output is correct
65 Correct 44 ms 6244 KB Output is correct
66 Correct 70 ms 14080 KB Output is correct
67 Correct 76 ms 14064 KB Output is correct
68 Correct 75 ms 14128 KB Output is correct
69 Correct 69 ms 14080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 272 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 10 ms 1204 KB Output is correct
7 Correct 170 ms 22668 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 0 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 8 ms 1180 KB Output is correct
13 Correct 234 ms 22448 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 4 ms 844 KB Output is correct
17 Correct 92 ms 12580 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 45 ms 6136 KB Output is correct
21 Correct 179 ms 22448 KB Output is correct
22 Correct 175 ms 22628 KB Output is correct
23 Correct 200 ms 22480 KB Output is correct
24 Correct 196 ms 22436 KB Output is correct
25 Correct 74 ms 12524 KB Output is correct
26 Correct 71 ms 12536 KB Output is correct
27 Correct 183 ms 22460 KB Output is correct
28 Correct 215 ms 22512 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 1 ms 296 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 0 ms 292 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 7 ms 1172 KB Output is correct
37 Correct 192 ms 22564 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 8 ms 1204 KB Output is correct
41 Correct 187 ms 22536 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 7 ms 820 KB Output is correct
45 Correct 101 ms 12704 KB Output is correct
46 Correct 1 ms 292 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 44 ms 6144 KB Output is correct
50 Correct 183 ms 22724 KB Output is correct
51 Correct 173 ms 22604 KB Output is correct
52 Correct 175 ms 22532 KB Output is correct
53 Correct 85 ms 12808 KB Output is correct
54 Correct 76 ms 12724 KB Output is correct
55 Correct 173 ms 22520 KB Output is correct
56 Correct 190 ms 22568 KB Output is correct
57 Correct 72 ms 12712 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 1 ms 296 KB Output is correct
61 Correct 52 ms 6096 KB Output is correct
62 Correct 192 ms 22468 KB Output is correct
63 Correct 207 ms 22552 KB Output is correct
64 Correct 182 ms 22468 KB Output is correct
65 Correct 0 ms 204 KB Output is correct
66 Correct 47 ms 6092 KB Output is correct
67 Correct 174 ms 22556 KB Output is correct
68 Correct 186 ms 22520 KB Output is correct
69 Correct 197 ms 22728 KB Output is correct
70 Correct 0 ms 204 KB Output is correct
71 Correct 0 ms 204 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 51 ms 6188 KB Output is correct
74 Correct 189 ms 24008 KB Output is correct
75 Correct 177 ms 24008 KB Output is correct
76 Correct 178 ms 24004 KB Output is correct
77 Correct 175 ms 23968 KB Output is correct
78 Correct 1 ms 296 KB Output is correct
79 Correct 0 ms 204 KB Output is correct
80 Correct 4 ms 844 KB Output is correct
81 Correct 96 ms 12716 KB Output is correct
82 Correct 1 ms 300 KB Output is correct
83 Correct 0 ms 204 KB Output is correct
84 Correct 0 ms 204 KB Output is correct
85 Correct 44 ms 6244 KB Output is correct
86 Correct 70 ms 14080 KB Output is correct
87 Correct 76 ms 14064 KB Output is correct
88 Correct 75 ms 14128 KB Output is correct
89 Correct 69 ms 14080 KB Output is correct
90 Correct 1 ms 204 KB Output is correct
91 Correct 1 ms 204 KB Output is correct
92 Correct 4 ms 588 KB Output is correct
93 Correct 75 ms 10100 KB Output is correct
94 Correct 0 ms 300 KB Output is correct
95 Correct 0 ms 204 KB Output is correct
96 Correct 0 ms 204 KB Output is correct
97 Correct 15 ms 2628 KB Output is correct
98 Correct 64 ms 10100 KB Output is correct
99 Correct 66 ms 10112 KB Output is correct
100 Correct 62 ms 10116 KB Output is correct
101 Correct 64 ms 10108 KB Output is correct
102 Correct 63 ms 10180 KB Output is correct
103 Correct 70 ms 10096 KB Output is correct
104 Correct 69 ms 10024 KB Output is correct
105 Correct 71 ms 10052 KB Output is correct