답안 #659715

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
659715 2022-11-19T06:30:06 Z Sohsoh84 Newspapers (CEOI21_newspapers) C++17
12 / 100
609 ms 252848 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pll;

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

const ll MAXN = 20;

int n, m, dist[1 << MAXN], t[1 << MAXN], r[1 << MAXN];
vector<int> adj[MAXN];
vector<pll> badj[1 << MAXN];

inline int f(int mask, int v) {
	mask = (mask | (1 << v)) ^ (1 << v);
	return r[mask];
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	if (m >= n) return cout << "NO" << endl, 0;

	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		adj[u - 1].push_back(v - 1);
		adj[v - 1].push_back(u - 1);
	}

	for (int mask = 0; mask < (1 << n); mask++)
		for (int i = 0; i < n; i++)
			if (mask & (1 << i))
				for (int u : adj[i])
					r[mask] |= (1 << u);

	for (int mask = 1; mask < (1 << n); mask++)
		for (int i = 0; i < n; i++)
			badj[f(mask, i)].push_back({mask, i});

	memset(dist, 63, sizeof dist);
	queue<int> q;

	dist[0] = 0;
	q.push(0);

	while (!q.empty()) {
		int v = q.front();
		q.pop();

		for (auto [u, x] : badj[v]) {
			if (dist[u] > dist[v] + 1) {
				dist[u] = dist[v] + 1;
				t[u] = x;
				q.push(u);
			}
		}
	}

	int mask = (1 << n) - 1;
	if (dist[mask] > MAXN * MAXN) return cout << "NO" << endl, 0;

	cout << "YES" << endl << dist[mask] << endl;
	while (mask) {
		cout << t[mask] + 1 << sep;
		mask = f(mask, t[mask]);
	}

	cout << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 29012 KB Output is correct
2 Correct 14 ms 29060 KB Output is correct
3 Correct 14 ms 28960 KB Output is correct
4 Correct 14 ms 29012 KB Output is correct
5 Correct 14 ms 28984 KB Output is correct
6 Correct 14 ms 29012 KB Output is correct
7 Correct 13 ms 24916 KB Output is correct
8 Correct 14 ms 29036 KB Output is correct
9 Correct 13 ms 29156 KB Output is correct
10 Correct 14 ms 29012 KB Output is correct
11 Correct 15 ms 28996 KB Output is correct
12 Correct 13 ms 28988 KB Output is correct
13 Correct 13 ms 29012 KB Output is correct
14 Correct 14 ms 29068 KB Output is correct
15 Correct 15 ms 29216 KB Output is correct
16 Correct 14 ms 29212 KB Output is correct
17 Correct 14 ms 29220 KB Output is correct
18 Correct 14 ms 29140 KB Output is correct
19 Correct 14 ms 29340 KB Output is correct
20 Correct 14 ms 29268 KB Output is correct
21 Correct 14 ms 29268 KB Output is correct
22 Correct 14 ms 29256 KB Output is correct
23 Correct 16 ms 29688 KB Output is correct
24 Correct 14 ms 29608 KB Output is correct
25 Correct 18 ms 29524 KB Output is correct
26 Correct 16 ms 29652 KB Output is correct
27 Correct 21 ms 30280 KB Output is correct
28 Correct 18 ms 30292 KB Output is correct
29 Correct 16 ms 30292 KB Output is correct
30 Correct 17 ms 30292 KB Output is correct
31 Correct 19 ms 31792 KB Output is correct
32 Correct 20 ms 31772 KB Output is correct
33 Correct 20 ms 31828 KB Output is correct
34 Correct 19 ms 31700 KB Output is correct
35 Correct 25 ms 34448 KB Output is correct
36 Correct 25 ms 34808 KB Output is correct
37 Correct 30 ms 34616 KB Output is correct
38 Correct 26 ms 34900 KB Output is correct
39 Correct 38 ms 40780 KB Output is correct
40 Correct 39 ms 41160 KB Output is correct
41 Correct 39 ms 40364 KB Output is correct
42 Correct 39 ms 40740 KB Output is correct
43 Correct 73 ms 53400 KB Output is correct
44 Correct 68 ms 52712 KB Output is correct
45 Correct 68 ms 52536 KB Output is correct
46 Correct 71 ms 53884 KB Output is correct
47 Correct 124 ms 78320 KB Output is correct
48 Correct 132 ms 78608 KB Output is correct
49 Correct 134 ms 78624 KB Output is correct
50 Correct 133 ms 80336 KB Output is correct
51 Correct 246 ms 131388 KB Output is correct
52 Correct 220 ms 130052 KB Output is correct
53 Correct 253 ms 130960 KB Output is correct
54 Correct 241 ms 123980 KB Output is correct
55 Correct 477 ms 243088 KB Output is correct
56 Correct 424 ms 226096 KB Output is correct
57 Correct 609 ms 252848 KB Output is correct
58 Correct 569 ms 238884 KB Output is correct
59 Correct 19 ms 24888 KB Output is correct
60 Correct 19 ms 24916 KB Output is correct
61 Correct 15 ms 24916 KB Output is correct
62 Correct 15 ms 24948 KB Output is correct
63 Correct 16 ms 24904 KB Output is correct
64 Correct 19 ms 24916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 29012 KB Output is correct
2 Correct 16 ms 28984 KB Output is correct
3 Correct 18 ms 29008 KB Output is correct
4 Correct 16 ms 29044 KB Output is correct
5 Correct 16 ms 29012 KB Output is correct
6 Correct 16 ms 29060 KB Output is correct
7 Correct 19 ms 28948 KB Output is correct
8 Correct 18 ms 29012 KB Output is correct
9 Correct 18 ms 29088 KB Output is correct
10 Correct 22 ms 29196 KB Output is correct
11 Runtime error 42 ms 50424 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 29012 KB Output is correct
2 Correct 14 ms 29060 KB Output is correct
3 Correct 14 ms 28960 KB Output is correct
4 Correct 14 ms 29012 KB Output is correct
5 Correct 14 ms 28984 KB Output is correct
6 Correct 14 ms 29012 KB Output is correct
7 Correct 13 ms 24916 KB Output is correct
8 Correct 14 ms 29036 KB Output is correct
9 Correct 13 ms 29156 KB Output is correct
10 Correct 14 ms 29012 KB Output is correct
11 Correct 15 ms 28996 KB Output is correct
12 Correct 13 ms 28988 KB Output is correct
13 Correct 13 ms 29012 KB Output is correct
14 Correct 14 ms 29068 KB Output is correct
15 Correct 15 ms 29216 KB Output is correct
16 Correct 14 ms 29212 KB Output is correct
17 Correct 14 ms 29220 KB Output is correct
18 Correct 14 ms 29140 KB Output is correct
19 Correct 14 ms 29340 KB Output is correct
20 Correct 14 ms 29268 KB Output is correct
21 Correct 14 ms 29268 KB Output is correct
22 Correct 14 ms 29256 KB Output is correct
23 Correct 16 ms 29688 KB Output is correct
24 Correct 14 ms 29608 KB Output is correct
25 Correct 18 ms 29524 KB Output is correct
26 Correct 16 ms 29652 KB Output is correct
27 Correct 21 ms 30280 KB Output is correct
28 Correct 18 ms 30292 KB Output is correct
29 Correct 16 ms 30292 KB Output is correct
30 Correct 17 ms 30292 KB Output is correct
31 Correct 19 ms 31792 KB Output is correct
32 Correct 20 ms 31772 KB Output is correct
33 Correct 20 ms 31828 KB Output is correct
34 Correct 19 ms 31700 KB Output is correct
35 Correct 25 ms 34448 KB Output is correct
36 Correct 25 ms 34808 KB Output is correct
37 Correct 30 ms 34616 KB Output is correct
38 Correct 26 ms 34900 KB Output is correct
39 Correct 38 ms 40780 KB Output is correct
40 Correct 39 ms 41160 KB Output is correct
41 Correct 39 ms 40364 KB Output is correct
42 Correct 39 ms 40740 KB Output is correct
43 Correct 73 ms 53400 KB Output is correct
44 Correct 68 ms 52712 KB Output is correct
45 Correct 68 ms 52536 KB Output is correct
46 Correct 71 ms 53884 KB Output is correct
47 Correct 124 ms 78320 KB Output is correct
48 Correct 132 ms 78608 KB Output is correct
49 Correct 134 ms 78624 KB Output is correct
50 Correct 133 ms 80336 KB Output is correct
51 Correct 246 ms 131388 KB Output is correct
52 Correct 220 ms 130052 KB Output is correct
53 Correct 253 ms 130960 KB Output is correct
54 Correct 241 ms 123980 KB Output is correct
55 Correct 477 ms 243088 KB Output is correct
56 Correct 424 ms 226096 KB Output is correct
57 Correct 609 ms 252848 KB Output is correct
58 Correct 569 ms 238884 KB Output is correct
59 Correct 19 ms 24888 KB Output is correct
60 Correct 19 ms 24916 KB Output is correct
61 Correct 15 ms 24916 KB Output is correct
62 Correct 15 ms 24948 KB Output is correct
63 Correct 16 ms 24904 KB Output is correct
64 Correct 19 ms 24916 KB Output is correct
65 Correct 18 ms 29048 KB Output is correct
66 Correct 17 ms 29048 KB Output is correct
67 Correct 18 ms 28980 KB Output is correct
68 Correct 19 ms 29020 KB Output is correct
69 Correct 17 ms 29048 KB Output is correct
70 Correct 17 ms 29052 KB Output is correct
71 Correct 14 ms 24952 KB Output is correct
72 Correct 16 ms 28988 KB Output is correct
73 Correct 17 ms 29096 KB Output is correct
74 Correct 15 ms 29048 KB Output is correct
75 Correct 17 ms 29004 KB Output is correct
76 Correct 16 ms 29048 KB Output is correct
77 Correct 15 ms 29052 KB Output is correct
78 Correct 15 ms 29012 KB Output is correct
79 Runtime error 44 ms 50380 KB Execution killed with signal 11
80 Halted 0 ms 0 KB -