답안 #601208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
601208 2022-07-21T13:10:49 Z yutabi 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
216 ms 22092 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;


#define pb push_back


int construct(std::vector<std::vector<int>> p)
{
	int n = p.size();

	std::vector<std::vector<int>> answer(n,vector <int> (n,0));

	vector <bool> v(n,0);

	vector <vector <int> > graphs;

	for(int i=0;i<n;i++)
	{
		if(v[i]==0)
		{
			graphs.pb({});

			stack <int> st;

			st.push(i);

			while(st.size())
			{
				int node=st.top();
				st.pop();

				v[node]=1;
				graphs.back().pb(node);

				for(int j=0;j<n;j++)
				{
					if(node!=j && p[node][j]>0 && v[j]==0)
					{
						st.push(j);
						v[j]=1;
					}
				}
			}
		}
	}

	for(int i=0;i<graphs.size();i++)
	{
		for(int j=0;j<graphs[i].size();j++)
		{
			for(int k=j+1;k<graphs[i].size();k++)
			{
				if(p[graphs[i][j]][graphs[i][k]]==0)
				{
					return 0;
				}
			}
		}

		int val=-1;

		for(int j=0;j<graphs[i].size();j++)
		{
			for(int k=j+1;k<graphs[i].size();k++)
			{
				int nw=p[graphs[i][j]][graphs[i][k]];

				if(nw==2)
				{
					if(val==3)
					{
						return 0;
					}

					val=2;
				}

				if(nw==3)
				{
					if(val==2)
					{
						return 0;
					}

					val=3;
				}
			}
		}

		vector <vector <int> > trees;

		v=vector <bool> (graphs[i].size(),0);

		for(int j=0;j<graphs[i].size();j++)
		{
			if(v[j]==0)
			{
				trees.pb({});

				stack <int> st;

				st.push(j);

				while(st.size())
				{
					int node=st.top();
					st.pop();

					v[node]=1;
					trees.back().pb(graphs[i][node]);

					for(int k=0;k<graphs[i].size();k++)
					{
						if(node!=k && p[graphs[i][node]][graphs[i][k]]==1 && v[k]==0)
						{
							st.push(k);
							v[k]=1;
						}
					}
				}
			}
		}

		if(trees.size()==2)
		{
			return 0;
		}

		if(val==3/* && trees.size()==3*/)
		{
			return 0;
		}

		for(int j=0;j<trees.size();j++)
		{
			for(int k=0;k<trees[j].size();k++)
			{
				for(int l=k+1;l<trees[j].size();l++)
				{
					if(p[trees[j][k]][trees[j][l]]!=1)
					{
						return 0;
					}
				}
			}
		}

		for(int j=0;j<trees.size();j++)
		{
			for(int k=0;k+1<trees[j].size();k++)
			{
				answer[trees[j][k]][trees[j][k+1]]=1;
				answer[trees[j][k+1]][trees[j][k]]=1;
			}

			answer[trees[(j)%trees.size()][0]][trees[(j+1)%trees.size()][0]]=1;
			answer[trees[(j+1)%trees.size()][0]][trees[(j)%trees.size()][0]]=1;
		}

		if(val==3)
		{
			answer[trees[0][0]][trees[2][0]]=1;
			answer[trees[2][0]][trees[0][0]]=1;
		}
	}

	for(int i=0;i<n;i++)
	{
		answer[i][i]=0;
	}

	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:49:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |  for(int i=0;i<graphs.size();i++)
      |              ~^~~~~~~~~~~~~~
supertrees.cpp:51:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   for(int j=0;j<graphs[i].size();j++)
      |               ~^~~~~~~~~~~~~~~~~
supertrees.cpp:53:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |    for(int k=j+1;k<graphs[i].size();k++)
      |                  ~^~~~~~~~~~~~~~~~~
supertrees.cpp:64:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |   for(int j=0;j<graphs[i].size();j++)
      |               ~^~~~~~~~~~~~~~~~~
supertrees.cpp:66:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |    for(int k=j+1;k<graphs[i].size();k++)
      |                  ~^~~~~~~~~~~~~~~~~
supertrees.cpp:96:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |   for(int j=0;j<graphs[i].size();j++)
      |               ~^~~~~~~~~~~~~~~~~
supertrees.cpp:114:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |      for(int k=0;k<graphs[i].size();k++)
      |                  ~^~~~~~~~~~~~~~~~~
supertrees.cpp:136:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  136 |   for(int j=0;j<trees.size();j++)
      |               ~^~~~~~~~~~~~~
supertrees.cpp:138:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  138 |    for(int k=0;k<trees[j].size();k++)
      |                ~^~~~~~~~~~~~~~~~
supertrees.cpp:140:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  140 |     for(int l=k+1;l<trees[j].size();l++)
      |                   ~^~~~~~~~~~~~~~~~
supertrees.cpp:150:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  150 |   for(int j=0;j<trees.size();j++)
      |               ~^~~~~~~~~~~~~
supertrees.cpp:152:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  152 |    for(int k=0;k+1<trees[j].size();k++)
      |                ~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 9 ms 1124 KB Output is correct
7 Correct 176 ms 22016 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 9 ms 1124 KB Output is correct
7 Correct 176 ms 22016 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 9 ms 1108 KB Output is correct
13 Correct 176 ms 22000 KB Output is correct
14 Correct 1 ms 260 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 96 ms 12036 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 45 ms 5764 KB Output is correct
21 Correct 171 ms 22008 KB Output is correct
22 Correct 176 ms 22024 KB Output is correct
23 Correct 191 ms 21968 KB Output is correct
24 Correct 171 ms 21980 KB Output is correct
25 Correct 96 ms 12108 KB Output is correct
26 Correct 73 ms 12164 KB Output is correct
27 Correct 181 ms 22028 KB Output is correct
28 Correct 216 ms 22020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
8 Correct 8 ms 1108 KB Output is correct
9 Correct 171 ms 22020 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1160 KB Output is correct
13 Correct 191 ms 22028 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 89 ms 12048 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 43 ms 5720 KB Output is correct
22 Correct 186 ms 22060 KB Output is correct
23 Correct 183 ms 22028 KB Output is correct
24 Correct 179 ms 22072 KB Output is correct
25 Correct 94 ms 12164 KB Output is correct
26 Correct 80 ms 12036 KB Output is correct
27 Correct 182 ms 22040 KB Output is correct
28 Correct 176 ms 22028 KB Output is correct
29 Correct 76 ms 12172 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 44 ms 5744 KB Output is correct
5 Correct 176 ms 22020 KB Output is correct
6 Correct 174 ms 22020 KB Output is correct
7 Correct 185 ms 21992 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 45 ms 5688 KB Output is correct
10 Correct 172 ms 22036 KB Output is correct
11 Correct 181 ms 21964 KB Output is correct
12 Correct 183 ms 22000 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 47 ms 5764 KB Output is correct
17 Correct 179 ms 21976 KB Output is correct
18 Correct 169 ms 22020 KB Output is correct
19 Correct 195 ms 22032 KB Output is correct
20 Correct 173 ms 22092 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 9 ms 1124 KB Output is correct
7 Correct 176 ms 22016 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 9 ms 1108 KB Output is correct
13 Correct 176 ms 22000 KB Output is correct
14 Correct 1 ms 260 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 96 ms 12036 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 45 ms 5764 KB Output is correct
21 Correct 171 ms 22008 KB Output is correct
22 Correct 176 ms 22024 KB Output is correct
23 Correct 191 ms 21968 KB Output is correct
24 Correct 171 ms 21980 KB Output is correct
25 Correct 96 ms 12108 KB Output is correct
26 Correct 73 ms 12164 KB Output is correct
27 Correct 181 ms 22028 KB Output is correct
28 Correct 216 ms 22020 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 8 ms 1108 KB Output is correct
37 Correct 171 ms 22020 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 8 ms 1160 KB Output is correct
41 Correct 191 ms 22028 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 89 ms 12048 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 43 ms 5720 KB Output is correct
50 Correct 186 ms 22060 KB Output is correct
51 Correct 183 ms 22028 KB Output is correct
52 Correct 179 ms 22072 KB Output is correct
53 Correct 94 ms 12164 KB Output is correct
54 Correct 80 ms 12036 KB Output is correct
55 Correct 182 ms 22040 KB Output is correct
56 Correct 176 ms 22028 KB Output is correct
57 Correct 76 ms 12172 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 5 ms 724 KB Output is correct
61 Correct 115 ms 12032 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 45 ms 5760 KB Output is correct
66 Correct 76 ms 12048 KB Output is correct
67 Correct 74 ms 12140 KB Output is correct
68 Correct 72 ms 12040 KB Output is correct
69 Correct 84 ms 12160 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 9 ms 1124 KB Output is correct
7 Correct 176 ms 22016 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 9 ms 1108 KB Output is correct
13 Correct 176 ms 22000 KB Output is correct
14 Correct 1 ms 260 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 96 ms 12036 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 45 ms 5764 KB Output is correct
21 Correct 171 ms 22008 KB Output is correct
22 Correct 176 ms 22024 KB Output is correct
23 Correct 191 ms 21968 KB Output is correct
24 Correct 171 ms 21980 KB Output is correct
25 Correct 96 ms 12108 KB Output is correct
26 Correct 73 ms 12164 KB Output is correct
27 Correct 181 ms 22028 KB Output is correct
28 Correct 216 ms 22020 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 8 ms 1108 KB Output is correct
37 Correct 171 ms 22020 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 8 ms 1160 KB Output is correct
41 Correct 191 ms 22028 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 89 ms 12048 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 43 ms 5720 KB Output is correct
50 Correct 186 ms 22060 KB Output is correct
51 Correct 183 ms 22028 KB Output is correct
52 Correct 179 ms 22072 KB Output is correct
53 Correct 94 ms 12164 KB Output is correct
54 Correct 80 ms 12036 KB Output is correct
55 Correct 182 ms 22040 KB Output is correct
56 Correct 176 ms 22028 KB Output is correct
57 Correct 76 ms 12172 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 44 ms 5744 KB Output is correct
62 Correct 176 ms 22020 KB Output is correct
63 Correct 174 ms 22020 KB Output is correct
64 Correct 185 ms 21992 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 45 ms 5688 KB Output is correct
67 Correct 172 ms 22036 KB Output is correct
68 Correct 181 ms 21964 KB Output is correct
69 Correct 183 ms 22000 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 47 ms 5764 KB Output is correct
74 Correct 179 ms 21976 KB Output is correct
75 Correct 169 ms 22020 KB Output is correct
76 Correct 195 ms 22032 KB Output is correct
77 Correct 173 ms 22092 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 5 ms 724 KB Output is correct
81 Correct 115 ms 12032 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 45 ms 5760 KB Output is correct
86 Correct 76 ms 12048 KB Output is correct
87 Correct 74 ms 12140 KB Output is correct
88 Correct 72 ms 12040 KB Output is correct
89 Correct 84 ms 12160 KB Output is correct
90 Correct 0 ms 212 KB Output is correct
91 Correct 0 ms 212 KB Output is correct
92 Correct 4 ms 724 KB Output is correct
93 Correct 84 ms 12044 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 19 ms 3276 KB Output is correct
98 Correct 101 ms 12032 KB Output is correct
99 Correct 93 ms 12036 KB Output is correct
100 Correct 74 ms 12040 KB Output is correct
101 Correct 71 ms 12160 KB Output is correct
102 Correct 80 ms 12172 KB Output is correct
103 Correct 83 ms 14080 KB Output is correct
104 Correct 90 ms 14064 KB Output is correct
105 Correct 100 ms 14000 KB Output is correct