Submission #286268

# Submission time Handle Problem Language Result Execution time Memory
286268 2020-08-30T08:55:47 Z spdskatr Village (BOI20_village) C++14
6 / 100
71 ms 384 KB
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cassert>

using namespace std;

int N;
int adj[15][15], p[15];
int minval = 2069696969, mina[15];
int maxval = 0, maxa[15];

int main() {
	scanf("%d", &N);
	assert(N <= 10);
	for (int i = 1; i <= N; i++) for (int j = i+1; j <= N; j++) adj[i][j] = adj[j][i] = 69;
	for (int i = 0; i < N-1; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		adj[a][b] = adj[b][a] = 1;
	}
	for (int m = 1; m <= N; m++)
		for (int u = 1; u <= N; u++)
			for (int v = 1; v <= N; v++)
				adj[u][v] = min(adj[u][v], adj[u][m] + adj[m][v]);
	for (int i = 1; i <= N; i++) p[i-1] = i;
	do {
		int val = 0, rip = 0;
		for (int i = 1; i <= N; i++) if (p[i-1] == i) {
			rip = 1;
		}
		if (rip) continue;
		for (int i = 1; i <= N; i++) val += adj[i][p[i-1]];
		if (val > maxval) {
			maxval = val;
			for (int i = 0; i < N; i++) maxa[i] = p[i];
		}
		if (val < minval) {
			minval = val;
			for (int i = 0; i < N; i++) mina[i] = p[i];
		}
	} while (next_permutation(p, p+N));
	printf("%d %d\n", minval, maxval);
	for (int i = 0; i < N; i++) {
		if (i == 0) printf("%d", mina[i]);
		else printf(" %d", maxa[i]);
	} printf("\n");
	for (int i = 0; i < N; i++) {
		if (i == 0) printf("%d", maxa[i]);
		else printf(" %d", maxa[i]);
	} printf("\n");
}

Compilation message

Village.cpp: In function 'int main()':
Village.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
Village.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |   scanf("%d %d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 256 KB Partially correct
2 Partially correct 0 ms 256 KB Partially correct
3 Correct 0 ms 256 KB Output is correct
4 Partially correct 0 ms 256 KB Partially correct
5 Partially correct 1 ms 256 KB Partially correct
6 Partially correct 0 ms 256 KB Partially correct
7 Correct 0 ms 256 KB Output is correct
8 Partially correct 1 ms 256 KB Partially correct
9 Partially correct 7 ms 256 KB Partially correct
10 Partially correct 69 ms 256 KB Partially correct
11 Partially correct 69 ms 256 KB Partially correct
12 Partially correct 67 ms 256 KB Partially correct
13 Partially correct 71 ms 256 KB Partially correct
14 Correct 68 ms 256 KB Output is correct
15 Partially correct 68 ms 256 KB Partially correct
16 Partially correct 67 ms 352 KB Partially correct
17 Partially correct 67 ms 256 KB Partially correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 256 KB Partially correct
2 Partially correct 0 ms 256 KB Partially correct
3 Correct 0 ms 256 KB Output is correct
4 Partially correct 0 ms 256 KB Partially correct
5 Partially correct 1 ms 256 KB Partially correct
6 Partially correct 0 ms 256 KB Partially correct
7 Correct 0 ms 256 KB Output is correct
8 Partially correct 1 ms 256 KB Partially correct
9 Partially correct 7 ms 256 KB Partially correct
10 Partially correct 69 ms 256 KB Partially correct
11 Partially correct 69 ms 256 KB Partially correct
12 Partially correct 67 ms 256 KB Partially correct
13 Partially correct 71 ms 256 KB Partially correct
14 Correct 68 ms 256 KB Output is correct
15 Partially correct 68 ms 256 KB Partially correct
16 Partially correct 67 ms 352 KB Partially correct
17 Partially correct 67 ms 256 KB Partially correct
18 Runtime error 1 ms 384 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -