# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
857985 | 2023-10-07T08:41:11 Z | danikoynov | Newspapers (CEOI21_newspapers) | C++14 | 143 ms | 10844 KB |
#include<bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; void speed() { ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); } const int maxn = 1010; int n, m; void solve_chain() { if (n == 1) { cout << "YES" << endl; cout << 1 << endl; cout << 1 << endl; return; } if (n == 2) { cout << "YES" << endl; cout << 2 << endl; cout << 1 << " " << 1 << endl; return; } cout << "YES" << endl; cout << (n - 2) * 2 << endl; for (int i = 2; i < n; i ++) cout << i << " "; for (int i = n - 1; i > 1; i --) cout << i << " "; cout << endl; } vector < int > adj[maxn]; const int maxmask = (1 << 21); int dp[maxmask], from[maxmask], last[maxmask]; int transition_mask(int mask, int ver) { int new_mask = 0; if ((mask & (1 << (ver - 1))) > 0) mask -= (1 << (ver - 1)); for (int v = 1; v <= n; v ++) { if ((mask & (1 << (v - 1))) == 0) continue; for (int u : adj[v]) new_mask |= (1 << (u - 1)); } return new_mask; } int used[maxn]; bool cycle; void dfs(int v, int p) { used[v] = 1; for (int u : adj[v]) { if (used[u] && u != p) cycle = true; if (!used[u]) dfs(u, v); } } int depth[maxn], md[maxn]; void calc(int v, int p) { md[v] = depth[v]; for (int u : adj[v]) { if (u == p) continue; depth[u] = depth[v] + 1; calc(u, v); md[v] = max(md[v], md[u]); } } void check_bad() { for (int v = 1; v <= n; v ++) { for (int i = 1; i <= n; i ++) depth[i] = md[i] = 0; calc(v, - 1); int cnt = 0; for (int u : adj[v]) { if (md[u] >= 3) cnt ++; } if (cnt > 2) { cout << "NO" << endl; exit(0); } } } void solve() { srand(time(NULL)); cin >> n >> m; if (n == 1) { cout << "YES" << endl; cout << 1 << endl; cout << 1 << endl; return; } for (int i = 1; i <= m; i ++) { int v, u; cin >> v >> u; //u = i + 1; //v = rand() % (i) + 1; //cout << v << " " << u << endl; adj[v].push_back(u); adj[u].push_back(v); } dfs(1, -1); if (cycle) { cout << "NO" << endl; return; } check_bad(); if (n > 20) { solve_chain(); return; } int base_mask = (1 << n) - 1; for (int mask = 0; mask < (1 << n); mask ++) dp[mask] = -1; dp[base_mask] = 0; queue < int > q; q.push(base_mask); while(!q.empty()) { int mask = q.front(); q.pop(); for (int i = 0; i < n; i ++) { int next_mask = transition_mask(mask, i + 1); if (dp[next_mask] == -1 ) { dp[next_mask] = dp[mask] + 1; from[next_mask] = i + 1; last[next_mask] = mask; q.push(next_mask); } } } if (dp[0] == -1) { cout << "NO" << endl; return; } vector < int > ord; int cur = 0; while(cur != base_mask) { ///cout << "step " << cur << " " << from[cur] << endl; ord.push_back(from[cur]); cur = last[cur]; } reverse(ord.begin(), ord.end()); cout << "YES" << endl; cout << ord.size() << endl; for (int cur : ord) cout << cur << " "; cout << endl; } int main() { solve(); return 0; } /** 8 7 1 2 2 3 1 4 4 5 1 6 6 7 6 8 10 9 1 2 1 3 1 4 2 5 2 6 3 7 3 8 4 9 4 10 20 19 1 2 2 3 2 4 1 5 5 6 5 7 6 8 7 9 8 10 5 11 8 12 6 13 12 14 14 15 2 16 12 17 4 18 9 19 2 20 10 9 1 2 2 4 1 5 5 6 5 7 6 8 7 9 8 3 9 10 */
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 4444 KB | Output is correct |
3 | Correct | 1 ms | 4444 KB | Output is correct |
4 | Correct | 1 ms | 4444 KB | Output is correct |
5 | Correct | 1 ms | 4444 KB | Output is correct |
6 | Correct | 1 ms | 4444 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 4444 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 4444 KB | Output is correct |
11 | Correct | 1 ms | 4444 KB | Output is correct |
12 | Correct | 1 ms | 4444 KB | Output is correct |
13 | Correct | 1 ms | 4440 KB | Output is correct |
14 | Correct | 1 ms | 4444 KB | Output is correct |
15 | Correct | 1 ms | 4444 KB | Output is correct |
16 | Correct | 1 ms | 4444 KB | Output is correct |
17 | Correct | 1 ms | 4444 KB | Output is correct |
18 | Correct | 1 ms | 4444 KB | Output is correct |
19 | Correct | 1 ms | 4696 KB | Output is correct |
20 | Correct | 1 ms | 4444 KB | Output is correct |
21 | Correct | 1 ms | 4444 KB | Output is correct |
22 | Correct | 1 ms | 4444 KB | Output is correct |
23 | Correct | 1 ms | 4444 KB | Output is correct |
24 | Correct | 1 ms | 4444 KB | Output is correct |
25 | Correct | 1 ms | 4444 KB | Output is correct |
26 | Correct | 1 ms | 4444 KB | Output is correct |
27 | Correct | 1 ms | 4444 KB | Output is correct |
28 | Correct | 1 ms | 4444 KB | Output is correct |
29 | Correct | 0 ms | 348 KB | Output is correct |
30 | Correct | 1 ms | 4444 KB | Output is correct |
31 | Correct | 1 ms | 4444 KB | Output is correct |
32 | Correct | 1 ms | 4444 KB | Output is correct |
33 | Correct | 1 ms | 4444 KB | Output is correct |
34 | Correct | 0 ms | 348 KB | Output is correct |
35 | Correct | 1 ms | 4700 KB | Output is correct |
36 | Correct | 1 ms | 4700 KB | Output is correct |
37 | Correct | 1 ms | 4444 KB | Output is correct |
38 | Correct | 1 ms | 4700 KB | Output is correct |
39 | Correct | 1 ms | 10840 KB | Output is correct |
40 | Correct | 2 ms | 10844 KB | Output is correct |
41 | Correct | 1 ms | 10584 KB | Output is correct |
42 | Correct | 2 ms | 10844 KB | Output is correct |
43 | Correct | 2 ms | 10588 KB | Output is correct |
44 | Correct | 2 ms | 10716 KB | Output is correct |
45 | Correct | 0 ms | 348 KB | Output is correct |
46 | Correct | 0 ms | 348 KB | Output is correct |
47 | Correct | 0 ms | 348 KB | Output is correct |
48 | Correct | 2 ms | 10588 KB | Output is correct |
49 | Correct | 0 ms | 348 KB | Output is correct |
50 | Correct | 0 ms | 348 KB | Output is correct |
51 | Correct | 2 ms | 10588 KB | Output is correct |
52 | Correct | 0 ms | 412 KB | Output is correct |
53 | Correct | 1 ms | 348 KB | Output is correct |
54 | Correct | 2 ms | 10588 KB | Output is correct |
55 | Correct | 0 ms | 348 KB | Output is correct |
56 | Correct | 0 ms | 348 KB | Output is correct |
57 | Correct | 0 ms | 348 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 | 0 ms | 348 KB | Output is correct |
62 | Correct | 0 ms | 348 KB | Output is correct |
63 | Correct | 0 ms | 348 KB | Output is correct |
64 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 4444 KB | Output is correct |
3 | Correct | 1 ms | 4444 KB | Output is correct |
4 | Correct | 1 ms | 4444 KB | Output is correct |
5 | Correct | 1 ms | 4444 KB | Output is correct |
6 | Correct | 1 ms | 4440 KB | Output is correct |
7 | Correct | 1 ms | 4444 KB | Output is correct |
8 | Correct | 1 ms | 4444 KB | Output is correct |
9 | Correct | 1 ms | 4444 KB | Output is correct |
10 | Correct | 1 ms | 4444 KB | Output is correct |
11 | Correct | 8 ms | 344 KB | Output is correct |
12 | Correct | 3 ms | 348 KB | Output is correct |
13 | Correct | 4 ms | 348 KB | Output is correct |
14 | Correct | 4 ms | 348 KB | Output is correct |
15 | Correct | 5 ms | 544 KB | Output is correct |
16 | Correct | 9 ms | 348 KB | Output is correct |
17 | Correct | 9 ms | 344 KB | Output is correct |
18 | Correct | 9 ms | 348 KB | Output is correct |
19 | Correct | 9 ms | 344 KB | Output is correct |
20 | Correct | 9 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 4444 KB | Output is correct |
3 | Correct | 1 ms | 4444 KB | Output is correct |
4 | Correct | 1 ms | 4444 KB | Output is correct |
5 | Correct | 1 ms | 4444 KB | Output is correct |
6 | Correct | 1 ms | 4444 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 4444 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 4444 KB | Output is correct |
11 | Correct | 1 ms | 4444 KB | Output is correct |
12 | Correct | 1 ms | 4444 KB | Output is correct |
13 | Correct | 1 ms | 4440 KB | Output is correct |
14 | Correct | 1 ms | 4444 KB | Output is correct |
15 | Correct | 1 ms | 4444 KB | Output is correct |
16 | Correct | 1 ms | 4444 KB | Output is correct |
17 | Correct | 1 ms | 4444 KB | Output is correct |
18 | Correct | 1 ms | 4444 KB | Output is correct |
19 | Correct | 1 ms | 4696 KB | Output is correct |
20 | Correct | 1 ms | 4444 KB | Output is correct |
21 | Correct | 1 ms | 4444 KB | Output is correct |
22 | Correct | 1 ms | 4444 KB | Output is correct |
23 | Correct | 1 ms | 4444 KB | Output is correct |
24 | Correct | 1 ms | 4444 KB | Output is correct |
25 | Correct | 1 ms | 4444 KB | Output is correct |
26 | Correct | 1 ms | 4444 KB | Output is correct |
27 | Correct | 1 ms | 4444 KB | Output is correct |
28 | Correct | 1 ms | 4444 KB | Output is correct |
29 | Correct | 0 ms | 348 KB | Output is correct |
30 | Correct | 1 ms | 4444 KB | Output is correct |
31 | Correct | 1 ms | 4444 KB | Output is correct |
32 | Correct | 1 ms | 4444 KB | Output is correct |
33 | Correct | 1 ms | 4444 KB | Output is correct |
34 | Correct | 0 ms | 348 KB | Output is correct |
35 | Correct | 1 ms | 4700 KB | Output is correct |
36 | Correct | 1 ms | 4700 KB | Output is correct |
37 | Correct | 1 ms | 4444 KB | Output is correct |
38 | Correct | 1 ms | 4700 KB | Output is correct |
39 | Correct | 1 ms | 10840 KB | Output is correct |
40 | Correct | 2 ms | 10844 KB | Output is correct |
41 | Correct | 1 ms | 10584 KB | Output is correct |
42 | Correct | 2 ms | 10844 KB | Output is correct |
43 | Correct | 2 ms | 10588 KB | Output is correct |
44 | Correct | 2 ms | 10716 KB | Output is correct |
45 | Correct | 0 ms | 348 KB | Output is correct |
46 | Correct | 0 ms | 348 KB | Output is correct |
47 | Correct | 0 ms | 348 KB | Output is correct |
48 | Correct | 2 ms | 10588 KB | Output is correct |
49 | Correct | 0 ms | 348 KB | Output is correct |
50 | Correct | 0 ms | 348 KB | Output is correct |
51 | Correct | 2 ms | 10588 KB | Output is correct |
52 | Correct | 0 ms | 412 KB | Output is correct |
53 | Correct | 1 ms | 348 KB | Output is correct |
54 | Correct | 2 ms | 10588 KB | Output is correct |
55 | Correct | 0 ms | 348 KB | Output is correct |
56 | Correct | 0 ms | 348 KB | Output is correct |
57 | Correct | 0 ms | 348 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 | 0 ms | 348 KB | Output is correct |
62 | Correct | 0 ms | 348 KB | Output is correct |
63 | Correct | 0 ms | 348 KB | Output is correct |
64 | Correct | 0 ms | 348 KB | Output is correct |
65 | Correct | 0 ms | 348 KB | Output is correct |
66 | Correct | 1 ms | 4444 KB | Output is correct |
67 | Correct | 1 ms | 4444 KB | Output is correct |
68 | Correct | 1 ms | 4444 KB | Output is correct |
69 | Correct | 1 ms | 4444 KB | Output is correct |
70 | Correct | 1 ms | 4444 KB | Output is correct |
71 | Correct | 0 ms | 600 KB | Output is correct |
72 | Correct | 1 ms | 4444 KB | Output is correct |
73 | Correct | 0 ms | 348 KB | Output is correct |
74 | Correct | 1 ms | 4444 KB | Output is correct |
75 | Correct | 1 ms | 4444 KB | Output is correct |
76 | Correct | 1 ms | 4440 KB | Output is correct |
77 | Correct | 1 ms | 4444 KB | Output is correct |
78 | Correct | 1 ms | 4444 KB | Output is correct |
79 | Correct | 1 ms | 348 KB | Output is correct |
80 | Correct | 1 ms | 348 KB | Output is correct |
81 | Correct | 1 ms | 344 KB | Output is correct |
82 | Correct | 1 ms | 348 KB | Output is correct |
83 | Correct | 1 ms | 348 KB | Output is correct |
84 | Correct | 1 ms | 348 KB | Output is correct |
85 | Correct | 1 ms | 344 KB | Output is correct |
86 | Correct | 1 ms | 348 KB | Output is correct |
87 | Correct | 1 ms | 472 KB | Output is correct |
88 | Correct | 1 ms | 348 KB | Output is correct |
89 | Partially correct | 8 ms | 600 KB | Failed to provide a successful strategy. |
90 | Partially correct | 7 ms | 344 KB | Failed to provide a successful strategy. |
91 | Partially correct | 6 ms | 348 KB | Failed to provide a successful strategy. |
92 | Partially correct | 8 ms | 604 KB | Failed to provide a successful strategy. |
93 | Partially correct | 8 ms | 344 KB | Failed to provide a successful strategy. |
94 | Partially correct | 6 ms | 344 KB | Failed to provide a successful strategy. |
95 | Partially correct | 9 ms | 344 KB | Failed to provide a successful strategy. |
96 | Partially correct | 9 ms | 348 KB | Failed to provide a successful strategy. |
97 | Partially correct | 5 ms | 348 KB | Failed to provide a successful strategy. |
98 | Partially correct | 8 ms | 472 KB | Failed to provide a successful strategy. |
99 | Partially correct | 7 ms | 348 KB | Failed to provide a successful strategy. |
100 | Partially correct | 7 ms | 344 KB | Failed to provide a successful strategy. |
101 | Partially correct | 6 ms | 348 KB | Failed to provide a successful strategy. |
102 | Partially correct | 7 ms | 348 KB | Failed to provide a successful strategy. |
103 | Partially correct | 7 ms | 348 KB | Failed to provide a successful strategy. |
104 | Partially correct | 5 ms | 348 KB | Failed to provide a successful strategy. |
105 | Partially correct | 6 ms | 348 KB | Failed to provide a successful strategy. |
106 | Partially correct | 7 ms | 348 KB | Failed to provide a successful strategy. |
107 | Partially correct | 6 ms | 348 KB | Failed to provide a successful strategy. |
108 | Partially correct | 9 ms | 348 KB | Failed to provide a successful strategy. |
109 | Partially correct | 7 ms | 500 KB | Failed to provide a successful strategy. |
110 | Partially correct | 7 ms | 356 KB | Failed to provide a successful strategy. |
111 | Partially correct | 6 ms | 348 KB | Failed to provide a successful strategy. |
112 | Partially correct | 6 ms | 344 KB | Failed to provide a successful strategy. |
113 | Partially correct | 9 ms | 348 KB | Failed to provide a successful strategy. |
114 | Partially correct | 7 ms | 348 KB | Failed to provide a successful strategy. |
115 | Partially correct | 6 ms | 348 KB | Failed to provide a successful strategy. |
116 | Partially correct | 7 ms | 348 KB | Failed to provide a successful strategy. |
117 | Partially correct | 9 ms | 348 KB | Failed to provide a successful strategy. |
118 | Partially correct | 10 ms | 348 KB | Failed to provide a successful strategy. |
119 | Partially correct | 7 ms | 348 KB | Failed to provide a successful strategy. |
120 | Partially correct | 8 ms | 348 KB | Failed to provide a successful strategy. |
121 | Partially correct | 8 ms | 552 KB | Failed to provide a successful strategy. |
122 | Partially correct | 6 ms | 348 KB | Failed to provide a successful strategy. |
123 | Partially correct | 6 ms | 348 KB | Failed to provide a successful strategy. |
124 | Partially correct | 8 ms | 348 KB | Failed to provide a successful strategy. |
125 | Partially correct | 5 ms | 348 KB | Failed to provide a successful strategy. |
126 | Partially correct | 6 ms | 348 KB | Failed to provide a successful strategy. |
127 | Partially correct | 5 ms | 348 KB | Failed to provide a successful strategy. |
128 | Partially correct | 9 ms | 348 KB | Failed to provide a successful strategy. |
129 | Correct | 1 ms | 348 KB | Output is correct |
130 | Correct | 1 ms | 348 KB | Output is correct |
131 | Correct | 1 ms | 344 KB | Output is correct |
132 | Correct | 1 ms | 348 KB | Output is correct |
133 | Correct | 1 ms | 348 KB | Output is correct |
134 | Correct | 28 ms | 2044 KB | Output is correct |
135 | Correct | 23 ms | 2140 KB | Output is correct |
136 | Correct | 62 ms | 5460 KB | Output is correct |
137 | Correct | 41 ms | 3412 KB | Output is correct |
138 | Correct | 73 ms | 5200 KB | Output is correct |
139 | Correct | 129 ms | 7944 KB | Output is correct |
140 | Correct | 18 ms | 1616 KB | Output is correct |
141 | Correct | 6 ms | 860 KB | Output is correct |
142 | Correct | 114 ms | 7496 KB | Output is correct |
143 | Correct | 143 ms | 8272 KB | Output is correct |
144 | Correct | 9 ms | 348 KB | Output is correct |
145 | Correct | 9 ms | 348 KB | Output is correct |