Submission #659713

# Submission time Handle Problem Language Result Execution time Memory
659713 2022-11-19T06:27:03 Z Sohsoh84 Newspapers (CEOI21_newspapers) C++17
0 / 100
1000 ms 239064 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];
vector<int> adj[MAXN];
vector<pll> badj[1 << MAXN];

inline int f(int mask, int v) {
	mask = (mask | (1 << v)) ^ (1 << v);
	vector<int> vec;

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

	return ans;
}

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 = 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;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 29012 KB Output is correct
2 Correct 15 ms 29012 KB Output is correct
3 Correct 14 ms 29012 KB Output is correct
4 Correct 13 ms 29012 KB Output is correct
5 Correct 14 ms 29012 KB Output is correct
6 Correct 14 ms 29068 KB Output is correct
7 Correct 13 ms 24880 KB Output is correct
8 Correct 14 ms 28988 KB Output is correct
9 Correct 15 ms 29140 KB Output is correct
10 Correct 15 ms 29040 KB Output is correct
11 Correct 15 ms 29052 KB Output is correct
12 Correct 15 ms 29012 KB Output is correct
13 Correct 14 ms 29044 KB Output is correct
14 Correct 15 ms 29032 KB Output is correct
15 Correct 15 ms 29180 KB Output is correct
16 Correct 16 ms 29096 KB Output is correct
17 Correct 14 ms 29140 KB Output is correct
18 Correct 15 ms 29140 KB Output is correct
19 Correct 18 ms 29420 KB Output is correct
20 Correct 17 ms 29260 KB Output is correct
21 Correct 16 ms 29300 KB Output is correct
22 Correct 17 ms 29304 KB Output is correct
23 Correct 16 ms 29652 KB Output is correct
24 Correct 17 ms 29576 KB Output is correct
25 Correct 16 ms 29560 KB Output is correct
26 Correct 17 ms 29644 KB Output is correct
27 Correct 18 ms 30328 KB Output is correct
28 Correct 19 ms 30332 KB Output is correct
29 Correct 19 ms 30332 KB Output is correct
30 Correct 19 ms 30256 KB Output is correct
31 Correct 26 ms 31832 KB Output is correct
32 Correct 26 ms 31596 KB Output is correct
33 Correct 26 ms 31776 KB Output is correct
34 Correct 27 ms 31532 KB Output is correct
35 Correct 39 ms 34384 KB Output is correct
36 Correct 38 ms 34672 KB Output is correct
37 Correct 38 ms 34508 KB Output is correct
38 Correct 44 ms 34672 KB Output is correct
39 Correct 69 ms 40576 KB Output is correct
40 Correct 69 ms 40832 KB Output is correct
41 Correct 67 ms 40016 KB Output is correct
42 Correct 74 ms 40440 KB Output is correct
43 Correct 122 ms 52844 KB Output is correct
44 Correct 129 ms 52212 KB Output is correct
45 Correct 123 ms 51952 KB Output is correct
46 Correct 126 ms 53452 KB Output is correct
47 Correct 242 ms 77200 KB Output is correct
48 Correct 251 ms 77676 KB Output is correct
49 Correct 248 ms 77640 KB Output is correct
50 Correct 237 ms 79368 KB Output is correct
51 Correct 519 ms 129352 KB Output is correct
52 Correct 508 ms 128124 KB Output is correct
53 Correct 513 ms 128964 KB Output is correct
54 Correct 517 ms 122248 KB Output is correct
55 Execution timed out 1063 ms 239064 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 29012 KB Output is correct
2 Correct 15 ms 29012 KB Output is correct
3 Correct 15 ms 29024 KB Output is correct
4 Correct 16 ms 29012 KB Output is correct
5 Correct 15 ms 29012 KB Output is correct
6 Correct 14 ms 29016 KB Output is correct
7 Correct 15 ms 29004 KB Output is correct
8 Correct 16 ms 28972 KB Output is correct
9 Correct 15 ms 29012 KB Output is correct
10 Correct 15 ms 29156 KB Output is correct
11 Runtime error 31 ms 50448 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 29012 KB Output is correct
2 Correct 15 ms 29012 KB Output is correct
3 Correct 14 ms 29012 KB Output is correct
4 Correct 13 ms 29012 KB Output is correct
5 Correct 14 ms 29012 KB Output is correct
6 Correct 14 ms 29068 KB Output is correct
7 Correct 13 ms 24880 KB Output is correct
8 Correct 14 ms 28988 KB Output is correct
9 Correct 15 ms 29140 KB Output is correct
10 Correct 15 ms 29040 KB Output is correct
11 Correct 15 ms 29052 KB Output is correct
12 Correct 15 ms 29012 KB Output is correct
13 Correct 14 ms 29044 KB Output is correct
14 Correct 15 ms 29032 KB Output is correct
15 Correct 15 ms 29180 KB Output is correct
16 Correct 16 ms 29096 KB Output is correct
17 Correct 14 ms 29140 KB Output is correct
18 Correct 15 ms 29140 KB Output is correct
19 Correct 18 ms 29420 KB Output is correct
20 Correct 17 ms 29260 KB Output is correct
21 Correct 16 ms 29300 KB Output is correct
22 Correct 17 ms 29304 KB Output is correct
23 Correct 16 ms 29652 KB Output is correct
24 Correct 17 ms 29576 KB Output is correct
25 Correct 16 ms 29560 KB Output is correct
26 Correct 17 ms 29644 KB Output is correct
27 Correct 18 ms 30328 KB Output is correct
28 Correct 19 ms 30332 KB Output is correct
29 Correct 19 ms 30332 KB Output is correct
30 Correct 19 ms 30256 KB Output is correct
31 Correct 26 ms 31832 KB Output is correct
32 Correct 26 ms 31596 KB Output is correct
33 Correct 26 ms 31776 KB Output is correct
34 Correct 27 ms 31532 KB Output is correct
35 Correct 39 ms 34384 KB Output is correct
36 Correct 38 ms 34672 KB Output is correct
37 Correct 38 ms 34508 KB Output is correct
38 Correct 44 ms 34672 KB Output is correct
39 Correct 69 ms 40576 KB Output is correct
40 Correct 69 ms 40832 KB Output is correct
41 Correct 67 ms 40016 KB Output is correct
42 Correct 74 ms 40440 KB Output is correct
43 Correct 122 ms 52844 KB Output is correct
44 Correct 129 ms 52212 KB Output is correct
45 Correct 123 ms 51952 KB Output is correct
46 Correct 126 ms 53452 KB Output is correct
47 Correct 242 ms 77200 KB Output is correct
48 Correct 251 ms 77676 KB Output is correct
49 Correct 248 ms 77640 KB Output is correct
50 Correct 237 ms 79368 KB Output is correct
51 Correct 519 ms 129352 KB Output is correct
52 Correct 508 ms 128124 KB Output is correct
53 Correct 513 ms 128964 KB Output is correct
54 Correct 517 ms 122248 KB Output is correct
55 Execution timed out 1063 ms 239064 KB Time limit exceeded
56 Halted 0 ms 0 KB -