답안 #783592

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
783592 2023-07-15T04:37:47 Z pravcoder 슈퍼트리 잇기 (IOI20_supertrees) C++14
11 / 100
172 ms 23928 KB
#include "supertrees.h"
#include <vector>

using namespace std;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> v2i;

int construct(v2i p) {
	int n = p.size();
	v2i answer;
	for (int i = 0; i < n; i++) {
		vi row;
		row.resize(n);
		answer.push_back(row);
	}

	//sub 2

	vi part(n);
	v2i parts;
	int next = 0;
	int nextpart;
	vb visited(n);
	int v = 0;
	int pnum = 0;

	part[0] = 1;

	while (v < n) {
		
		int current = next;
		for (int i = 0; i < n; i++)
		{
			if (p[current][i]) {
				if (part[i] == -1) return 0;
				if (!visited[i]){
					part[i] = 1;
					next = i;
				}
			} else {
				if (part[i] == 1) return 0;
				if (!visited[i]){
					part[i] = -1;
					nextpart = i;
				}
			}
		}
		visited[current] = 1;
		v++;
		if (next == current) {
			next = nextpart;
			parts.push_back({});
			for (int i = 0; i < n; i++)
			{
				if (part[i] == 1) parts[pnum].push_back(i);
			}
			pnum++;			
			part.clear();
			part.resize(n);
			part[next] = 1;
		}
	}

	for (auto part : parts)
	{
		for (int i = 0; i < part.size() - 1; i++)
		{
			answer[part[i]][part[i + 1]] = 1;
			answer[part[i + 1]][part[i]] = 1;
		}
		
	}
	
	
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(v2i)':
supertrees.cpp:68:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   for (int i = 0; i < part.size() - 1; i++)
      |                   ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:62:13: warning: 'nextpart' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |    part[next] = 1;
      |             ^
# 결과 실행 시간 메모리 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 1268 KB Output is correct
7 Correct 172 ms 23928 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 1268 KB Output is correct
7 Correct 172 ms 23928 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 1 ms 212 KB Output is correct
12 Correct 7 ms 1140 KB Output is correct
13 Correct 139 ms 22012 KB Output is correct
14 Incorrect 1 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 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Too few ways to get from 0 to 1, should be 2 found 1
3 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 1268 KB Output is correct
7 Correct 172 ms 23928 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 1 ms 212 KB Output is correct
12 Correct 7 ms 1140 KB Output is correct
13 Correct 139 ms 22012 KB Output is correct
14 Incorrect 1 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 1268 KB Output is correct
7 Correct 172 ms 23928 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 1 ms 212 KB Output is correct
12 Correct 7 ms 1140 KB Output is correct
13 Correct 139 ms 22012 KB Output is correct
14 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -