답안 #1079261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1079261 2024-08-28T12:26:04 Z Jawad_Akbar_JJ 슈퍼트리 잇기 (IOI20_supertrees) C++17
40 / 100
135 ms 24276 KB
#include <iostream>
#include <vector>
#include "supertrees.h"

using namespace std;
const int NN = 1005;
vector<int> nei[NN];
int seen[NN], dfsd[NN];
int d[NN][NN], lab[NN];

void dfs(int u, int r){
	dfsd[u] = 1;
	d[r][u]++;

	for (int i : nei[u])
		if (!dfsd[i])
			dfs(i, r);
	dfsd[u] = 0;
}

int construct(vector<vector<int>> p){
	int n = p.size();
	vector<vector<int>> ans(n, vector<int> (n, 0)), comp, comp2;
	vector<int> out;

	int z = 0, o = 0, t = 0, th = 0; 
	for (int i=0;i<n;i++)
		for (int j=0;j<n;j++){
			z += p[i][j] == 0;
			o += p[i][j] == 1;
			t += p[i][j] == 2;
			th += p[i][j] == 3;
		}

	if (o and z + t + th == 0){
		for (int i=1;i<n;i++)
			ans[i-1][i] = ans[i][i-1] = 1;
		build(ans);
		return 1;
	}

	if (t + th == 0){

		for (int i=0;i<n;i++){
			int mx = 0, ind = -1;
			for (int k=0;k<comp.size();k++){
				int cnt = 0;
				for (int j : comp[k])
					cnt += p[i][j];
				if (cnt == 0)
					continue;
				if (mx > 0 or cnt != comp[k].size())
					return 0;
				ind = k;
				mx = cnt;
			}
			if (ind == -1)
				comp.push_back({i});
			else
				comp[ind].push_back(i);
		}

		for (auto v : comp)
			for (int j=1;j<v.size();j++)
				ans[v[j-1]][v[j]] = ans[v[j]][v[j-1]] = 1;
		build(ans);
		return 1;
	}

	if (o == n and th == 0){
		for (int i=0;i<n;i++){
			int mx = 0, ind = -1;
			for (int k=0;k<comp.size();k++){
				int cnt = 0;
				for (int j : comp[k])
					cnt += p[i][j] == 2;
				if (cnt == 0)
					continue;
				if (mx > 0 or cnt != comp[k].size())
					return 0;
				ind = k;
				mx = cnt;
			}
			if (ind == -1)
				comp.push_back({i});
			else
				comp[ind].push_back(i);
		}

		for (auto v : comp){
			for (int j=1;j<v.size();j++)
				ans[v[j-1]][v[j]] = ans[v[j]][v[j-1]] = 1;
			if (v.size() > 1)
				ans[v.back()][v[0]] = ans[v[0]][v.back()] = 1;
			if (v.size() == 2)
				return 0;
		}
		build(ans);
		return 1;
	}
	if (th)
		return 0;

	for (int i=0;i<n;i++){
		lab[i] = i;
		int mx = 0, ind = -1;
		for (int k=0;k<comp.size();k++){
			int cnt = 0;
			for (int j : comp[k])
				cnt += p[i][j] == 1;
			if (cnt == 0)
				continue;
			if (cnt == comp[k].size())
				ind = k;
		}
		if (ind == -1)
			comp.push_back({i});
		else
			comp[ind].push_back(i);
	}
	for (auto v : comp)
		for (int j=1;j<v.size();j++)
			ans[v[j]][v[j-1]] = ans[v[j-1]][v[j]] = 1, lab[v[j]] = v[0];

	comp.clear();

	for (int i=0;i<n;i++){
		if (seen[lab[i]])
			continue;
		int ind = -1;
		for (int k=0;k<comp.size();k++){
			int cnt = 0;
			for (int j : comp[k])
				cnt += p[i][j] == 2;
			if (cnt == 0)
				continue;
			if (cnt == comp[k].size())
				ind = k;
		}
		seen[lab[i]] = 1;
		if (ind == -1)
			comp.push_back({i});
		else
			comp[ind].push_back(i);
	}

	for (auto v : comp){
		if (v.size() == 2)
			return 0;
		for (int i=1;i<v.size();i++)
			ans[v[i]][v[i-1]] = ans[v[i-1]][v[i]] = 1;
		ans[v[0]][v.back()] = ans[v.back()][v[0]] = 1;
	}

	for (int i=0;i<n;i++)
		for (int j=0;j<n;j++)
			if (ans[i][j])
				nei[i].push_back(j);
	
	for (int i=0;i<n;i++)
		dfs(i, i);
	for (int i=0;i<n;i++)
		for (int j=0;j<n;j++)
			if (d[i][j] != p[i][j])
				return 0;
	build(ans);
	return 1;

}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:46:18: 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 k=0;k<comp.size();k++){
      |                 ~^~~~~~~~~~~~
supertrees.cpp:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     if (mx > 0 or cnt != comp[k].size())
      |                   ~~~~^~~~~~~~~~~~~~~~~
supertrees.cpp:64:18: 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=1;j<v.size();j++)
      |                 ~^~~~~~~~~
supertrees.cpp:73:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |    for (int k=0;k<comp.size();k++){
      |                 ~^~~~~~~~~~~~
supertrees.cpp:79:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     if (mx > 0 or cnt != comp[k].size())
      |                   ~~~~^~~~~~~~~~~~~~~~~
supertrees.cpp:91:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |    for (int j=1;j<v.size();j++)
      |                 ~^~~~~~~~~
supertrees.cpp:107:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |   for (int k=0;k<comp.size();k++){
      |                ~^~~~~~~~~~~~
supertrees.cpp:113:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |    if (cnt == comp[k].size())
      |        ~~~~^~~~~~~~~~~~~~~~~
supertrees.cpp:106:7: warning: unused variable 'mx' [-Wunused-variable]
  106 |   int mx = 0, ind = -1;
      |       ^~
supertrees.cpp:122:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |   for (int j=1;j<v.size();j++)
      |                ~^~~~~~~~~
supertrees.cpp:131:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  131 |   for (int k=0;k<comp.size();k++){
      |                ~^~~~~~~~~~~~
supertrees.cpp:137:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  137 |    if (cnt == comp[k].size())
      |        ~~~~^~~~~~~~~~~~~~~~~
supertrees.cpp:150:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  150 |   for (int i=1;i<v.size();i++)
      |                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1412 KB Output is correct
7 Correct 119 ms 24144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1412 KB Output is correct
7 Correct 119 ms 24144 KB Output is correct
8 Correct 0 ms 472 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 1444 KB Output is correct
13 Correct 121 ms 24004 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 856 KB Output is correct
17 Correct 59 ms 14116 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 6268 KB Output is correct
21 Correct 133 ms 24152 KB Output is correct
22 Correct 116 ms 24148 KB Output is correct
23 Correct 133 ms 23972 KB Output is correct
24 Correct 121 ms 24144 KB Output is correct
25 Correct 55 ms 14160 KB Output is correct
26 Correct 52 ms 14164 KB Output is correct
27 Correct 127 ms 24276 KB Output is correct
28 Correct 135 ms 24148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 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 1 ms 600 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 6 ms 1372 KB Output is correct
9 Correct 118 ms 23972 KB Output is correct
10 Correct 0 ms 464 KB Output is correct
11 Correct 0 ms 472 KB Output is correct
12 Correct 5 ms 1220 KB Output is correct
13 Correct 117 ms 24144 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 62 ms 14160 KB Output is correct
18 Correct 1 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 30 ms 6360 KB Output is correct
22 Correct 130 ms 24088 KB Output is correct
23 Correct 119 ms 24144 KB Output is correct
24 Correct 121 ms 23964 KB Output is correct
25 Correct 54 ms 14236 KB Output is correct
26 Correct 52 ms 14164 KB Output is correct
27 Correct 122 ms 24144 KB Output is correct
28 Correct 129 ms 23964 KB Output is correct
29 Correct 52 ms 14116 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 38 ms 6260 KB Output is correct
5 Correct 114 ms 24148 KB Output is correct
6 Correct 115 ms 24148 KB Output is correct
7 Correct 126 ms 24148 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 30 ms 6432 KB Output is correct
10 Correct 118 ms 24104 KB Output is correct
11 Correct 118 ms 24144 KB Output is correct
12 Correct 125 ms 24144 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Incorrect 1 ms 344 KB b[4][4] is not 0
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1412 KB Output is correct
7 Correct 119 ms 24144 KB Output is correct
8 Correct 0 ms 472 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 1444 KB Output is correct
13 Correct 121 ms 24004 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 856 KB Output is correct
17 Correct 59 ms 14116 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 6268 KB Output is correct
21 Correct 133 ms 24152 KB Output is correct
22 Correct 116 ms 24148 KB Output is correct
23 Correct 133 ms 23972 KB Output is correct
24 Correct 121 ms 24144 KB Output is correct
25 Correct 55 ms 14160 KB Output is correct
26 Correct 52 ms 14164 KB Output is correct
27 Correct 127 ms 24276 KB Output is correct
28 Correct 135 ms 24148 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 6 ms 1372 KB Output is correct
37 Correct 118 ms 23972 KB Output is correct
38 Correct 0 ms 464 KB Output is correct
39 Correct 0 ms 472 KB Output is correct
40 Correct 5 ms 1220 KB Output is correct
41 Correct 117 ms 24144 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 62 ms 14160 KB Output is correct
46 Correct 1 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 30 ms 6360 KB Output is correct
50 Correct 130 ms 24088 KB Output is correct
51 Correct 119 ms 24144 KB Output is correct
52 Correct 121 ms 23964 KB Output is correct
53 Correct 54 ms 14236 KB Output is correct
54 Correct 52 ms 14164 KB Output is correct
55 Correct 122 ms 24144 KB Output is correct
56 Correct 129 ms 23964 KB Output is correct
57 Correct 52 ms 14116 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 3 ms 968 KB Output is correct
61 Correct 57 ms 14044 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Incorrect 0 ms 348 KB b[0][0] is not 0
64 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1412 KB Output is correct
7 Correct 119 ms 24144 KB Output is correct
8 Correct 0 ms 472 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 1444 KB Output is correct
13 Correct 121 ms 24004 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 856 KB Output is correct
17 Correct 59 ms 14116 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 6268 KB Output is correct
21 Correct 133 ms 24152 KB Output is correct
22 Correct 116 ms 24148 KB Output is correct
23 Correct 133 ms 23972 KB Output is correct
24 Correct 121 ms 24144 KB Output is correct
25 Correct 55 ms 14160 KB Output is correct
26 Correct 52 ms 14164 KB Output is correct
27 Correct 127 ms 24276 KB Output is correct
28 Correct 135 ms 24148 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 6 ms 1372 KB Output is correct
37 Correct 118 ms 23972 KB Output is correct
38 Correct 0 ms 464 KB Output is correct
39 Correct 0 ms 472 KB Output is correct
40 Correct 5 ms 1220 KB Output is correct
41 Correct 117 ms 24144 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 62 ms 14160 KB Output is correct
46 Correct 1 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 30 ms 6360 KB Output is correct
50 Correct 130 ms 24088 KB Output is correct
51 Correct 119 ms 24144 KB Output is correct
52 Correct 121 ms 23964 KB Output is correct
53 Correct 54 ms 14236 KB Output is correct
54 Correct 52 ms 14164 KB Output is correct
55 Correct 122 ms 24144 KB Output is correct
56 Correct 129 ms 23964 KB Output is correct
57 Correct 52 ms 14116 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 38 ms 6260 KB Output is correct
62 Correct 114 ms 24148 KB Output is correct
63 Correct 115 ms 24148 KB Output is correct
64 Correct 126 ms 24148 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 30 ms 6432 KB Output is correct
67 Correct 118 ms 24104 KB Output is correct
68 Correct 118 ms 24144 KB Output is correct
69 Correct 125 ms 24144 KB Output is correct
70 Correct 0 ms 344 KB Output is correct
71 Incorrect 1 ms 344 KB b[4][4] is not 0
72 Halted 0 ms 0 KB -