# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
868198 | 2023-10-30T18:21:15 Z | evenvalue | Newspapers (CEOI21_newspapers) | C++17 | 1 ms | 608 KB |
#include <bits/stdc++.h> using namespace std; #ifdef evenvalue #include "debug.h" #define debug(...) print(#__VA_ARGS__, __VA_ARGS__) #else #define debug(...) #endif using int64 = long long; using ld = long double; template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template<typename T> using max_heap = priority_queue<T, vector<T>, less<T>>; namespace Read { int Int() { int x; cin >> x; return x; } int64 Int64() { int64 x; cin >> x; return x; } char Char() { char c; cin >> c; return c; } string String() { string s; cin >> s; return s; } double Double() { return stod(String()); } ld LongDouble() { return stold(String()); } template<typename T1, typename T2> pair<T1, T2> Pair() { pair<T1, T2> p; cin >> p.first >> p.second; return p; } template<typename T> vector<T> Vec(const int n) { vector<T> v(n); for (T &x : v) { cin >> x; } return v; } template<typename T> vector<vector<T>> VecVec(const int n, const int m) { vector<vector<T>> v(n); for (vector<T> &vec : v) { vec = Vec<T>(m); } return v; } }// namespace Read constexpr int kInf = 1e9 + 10; constexpr int64 kInf64 = 1e15 + 10; constexpr int kMod = 1e9 + 7; constexpr int kMaxN = 2e5 + 10; pair<int, int> diameter(const vector<vector<int>> &g) { auto bfs = [&](int start) -> pair<int, int> { const int n = g.size(); vector<int> d(n, 0); vector<bool> visit(n, false); queue<int> q; q.push(start); while (not q.empty()) { int x = q.front(); q.pop(); visit[x] = true; for (int nbr : g[x]) { if (visit[nbr]) continue; q.push(nbr); d[nbr] = d[x] + 1; } } int far = distance(d.begin(), max_element(d.begin(), d.end())); return {d[far], far}; }; int x = bfs(0).second; return make_pair(x, bfs(x).second); } inline void solution() { const int n = Read::Int(); const int m = Read::Int(); if (m != n - 1) { cout << "NO\n"; return; } if (n == 1) { cout << "YES\n"; cout << 1 << '\n' << 1 << '\n'; return; } else if (n == 2 or n == 3) { cout << "YES\n"; cout << 2 << '\n'; cout << 1 << ' ' << 1 << '\n'; return; } vector<vector<int>> g(n); for (int i = 0; i < n - 1; i++) { const int x = Read::Int() - 1; const int y = Read::Int() - 1; g[x].push_back(y); g[y].push_back(x); } const auto ends = diameter(g); const int s = ends.first; const int t = ends.second; vector<int> ds(n); vector<int> dt(n); function<void(int, int, vector<int> &)> calc_dist = [&](const int x, const int p, vector<int> &d) { for (const int y : g[x]) { if (y == p) continue; d[y] = d[x] + 1; calc_dist(y, x, d); } }; calc_dist(s, -1, ds); calc_dist(t, -1, dt); for (int x = 0; x < n; x++) { sort(g[x].begin(), g[x].end(), [&](const int y, const int z) { return ds[y] + dt[y] != ds[t]; }); } vector<int> order; bool bad_star = false; function<int(int, int, int)> dfs = [&](const int x, const int p, int deviate_depth) { deviate_depth += (ds[x] + dt[x] != ds[t]); if (deviate_depth == 3) bad_star = true; for (const int y : g[x]) { if (y == p) continue; order.push_back(x); if (dfs(y, x, deviate_depth) == 1) order.pop_back(); } return deviate_depth; }; dfs(g[s][0], s, 0); for (int i = (int) order.size() - 1; i >= 0; i--) { order.push_back(order[i]); } if (bad_star) { cout << "NO\n"; return; } cout << "YES\n"; cout << order.size() << '\n'; for (const int x : order) { cout << x + 1 << ' '; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); //freopen(".in", "r", stdin); //freopen(".out", "w", stdout); cout << fixed << setprecision(10); int testcases = 1; //cin >> testcases; while (testcases--) { solution(); } }
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 352 KB | Output is correct |
2 | Correct | 0 ms | 360 KB | Output is correct |
3 | Correct | 0 ms | 360 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 452 KB | Output is correct |
8 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Partially correct | 0 ms | 344 KB | Failed to provide a successful strategy. |
11 | Correct | 0 ms | 344 KB | Output is correct |
12 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 344 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 0 ms | 604 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 0 ms | 348 KB | Output is correct |
22 | Correct | 0 ms | 344 KB | Output is correct |
23 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
24 | Correct | 1 ms | 344 KB | Output is correct |
25 | Partially correct | 0 ms | 344 KB | Failed to provide a successful strategy. |
26 | Partially correct | 1 ms | 608 KB | Failed to provide a successful strategy. |
27 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
28 | Correct | 0 ms | 456 KB | Output is correct |
29 | Correct | 0 ms | 348 KB | Output is correct |
30 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
31 | Correct | 0 ms | 348 KB | Output is correct |
32 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
33 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
34 | Correct | 0 ms | 348 KB | Output is correct |
35 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
36 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
37 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
38 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
39 | Partially correct | 0 ms | 600 KB | Failed to provide a successful strategy. |
40 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
41 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
42 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
43 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
44 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
45 | Correct | 0 ms | 348 KB | Output is correct |
46 | Correct | 0 ms | 348 KB | Output is correct |
47 | Correct | 0 ms | 344 KB | Output is correct |
48 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
49 | Correct | 0 ms | 348 KB | Output is correct |
50 | Correct | 0 ms | 348 KB | Output is correct |
51 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
52 | Correct | 0 ms | 348 KB | Output is correct |
53 | Correct | 0 ms | 452 KB | Output is correct |
54 | Correct | 0 ms | 348 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 | 364 KB | Output is correct |
60 | Correct | 1 ms | 600 KB | Output is correct |
61 | Correct | 1 ms | 604 KB | Output is correct |
62 | Correct | 0 ms | 348 KB | Output is correct |
63 | Correct | 0 ms | 452 KB | Output is correct |
64 | Correct | 0 ms | 600 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 604 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 1 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 604 KB | Output is correct |
17 | Correct | 1 ms | 604 KB | Output is correct |
18 | Correct | 1 ms | 604 KB | Output is correct |
19 | Correct | 1 ms | 604 KB | Output is correct |
20 | Correct | 1 ms | 604 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 352 KB | Output is correct |
2 | Correct | 0 ms | 360 KB | Output is correct |
3 | Correct | 0 ms | 360 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 452 KB | Output is correct |
8 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Partially correct | 0 ms | 344 KB | Failed to provide a successful strategy. |
11 | Correct | 0 ms | 344 KB | Output is correct |
12 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 344 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 0 ms | 604 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 0 ms | 348 KB | Output is correct |
22 | Correct | 0 ms | 344 KB | Output is correct |
23 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
24 | Correct | 1 ms | 344 KB | Output is correct |
25 | Partially correct | 0 ms | 344 KB | Failed to provide a successful strategy. |
26 | Partially correct | 1 ms | 608 KB | Failed to provide a successful strategy. |
27 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
28 | Correct | 0 ms | 456 KB | Output is correct |
29 | Correct | 0 ms | 348 KB | Output is correct |
30 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
31 | Correct | 0 ms | 348 KB | Output is correct |
32 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
33 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
34 | Correct | 0 ms | 348 KB | Output is correct |
35 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
36 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
37 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
38 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
39 | Partially correct | 0 ms | 600 KB | Failed to provide a successful strategy. |
40 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
41 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
42 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
43 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
44 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
45 | Correct | 0 ms | 348 KB | Output is correct |
46 | Correct | 0 ms | 348 KB | Output is correct |
47 | Correct | 0 ms | 344 KB | Output is correct |
48 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
49 | Correct | 0 ms | 348 KB | Output is correct |
50 | Correct | 0 ms | 348 KB | Output is correct |
51 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
52 | Correct | 0 ms | 348 KB | Output is correct |
53 | Correct | 0 ms | 452 KB | Output is correct |
54 | Correct | 0 ms | 348 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 | 364 KB | Output is correct |
60 | Correct | 1 ms | 600 KB | Output is correct |
61 | Correct | 1 ms | 604 KB | Output is correct |
62 | Correct | 0 ms | 348 KB | Output is correct |
63 | Correct | 0 ms | 452 KB | Output is correct |
64 | Correct | 0 ms | 600 KB | Output is correct |
65 | Correct | 1 ms | 348 KB | Output is correct |
66 | Correct | 1 ms | 344 KB | Output is correct |
67 | Correct | 0 ms | 348 KB | Output is correct |
68 | Correct | 0 ms | 348 KB | Output is correct |
69 | Correct | 0 ms | 348 KB | Output is correct |
70 | Correct | 0 ms | 348 KB | Output is correct |
71 | Correct | 0 ms | 348 KB | Output is correct |
72 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
73 | Correct | 0 ms | 348 KB | Output is correct |
74 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
75 | Correct | 0 ms | 348 KB | Output is correct |
76 | Partially correct | 0 ms | 348 KB | Failed to provide a successful strategy. |
77 | Correct | 0 ms | 460 KB | Output is correct |
78 | Correct | 0 ms | 456 KB | Output is correct |
79 | Correct | 1 ms | 348 KB | Output is correct |
80 | Correct | 1 ms | 348 KB | Output is correct |
81 | Correct | 0 ms | 348 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 | 348 KB | Output is correct |
86 | Correct | 1 ms | 512 KB | Output is correct |
87 | Correct | 1 ms | 348 KB | Output is correct |
88 | Correct | 1 ms | 460 KB | Output is correct |
89 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
90 | Partially correct | 1 ms | 352 KB | Failed to provide a successful strategy. |
91 | Partially correct | 1 ms | 352 KB | Failed to provide a successful strategy. |
92 | Partially correct | 1 ms | 352 KB | Failed to provide a successful strategy. |
93 | Partially correct | 1 ms | 352 KB | Failed to provide a successful strategy. |
94 | Partially correct | 1 ms | 352 KB | Failed to provide a successful strategy. |
95 | Partially correct | 1 ms | 608 KB | Failed to provide a successful strategy. |
96 | Partially correct | 1 ms | 608 KB | Failed to provide a successful strategy. |
97 | Partially correct | 1 ms | 532 KB | Failed to provide a successful strategy. |
98 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
99 | Partially correct | 1 ms | 344 KB | Failed to provide a successful strategy. |
100 | Partially correct | 1 ms | 344 KB | Failed to provide a successful strategy. |
101 | Partially correct | 1 ms | 460 KB | Failed to provide a successful strategy. |
102 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
103 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
104 | Partially correct | 1 ms | 344 KB | Failed to provide a successful strategy. |
105 | Partially correct | 1 ms | 344 KB | Failed to provide a successful strategy. |
106 | Partially correct | 1 ms | 344 KB | Failed to provide a successful strategy. |
107 | Partially correct | 1 ms | 344 KB | Failed to provide a successful strategy. |
108 | Partially correct | 1 ms | 604 KB | Failed to provide a successful strategy. |
109 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
110 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
111 | Partially correct | 1 ms | 600 KB | Failed to provide a successful strategy. |
112 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
113 | Partially correct | 1 ms | 604 KB | Failed to provide a successful strategy. |
114 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
115 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
116 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
117 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
118 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
119 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
120 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
121 | Partially correct | 1 ms | 600 KB | Failed to provide a successful strategy. |
122 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
123 | Partially correct | 1 ms | 344 KB | Failed to provide a successful strategy. |
124 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
125 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
126 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
127 | Partially correct | 1 ms | 348 KB | Failed to provide a successful strategy. |
128 | Partially correct | 1 ms | 600 KB | Failed to provide a successful strategy. |
129 | Correct | 1 ms | 348 KB | Output is correct |
130 | Correct | 1 ms | 528 KB | Output is correct |
131 | Correct | 1 ms | 348 KB | Output is correct |
132 | Correct | 1 ms | 348 KB | Output is correct |
133 | Correct | 1 ms | 348 KB | Output is correct |
134 | Correct | 0 ms | 348 KB | Output is correct |
135 | Correct | 0 ms | 344 KB | Output is correct |
136 | Correct | 0 ms | 348 KB | Output is correct |
137 | Correct | 1 ms | 600 KB | Output is correct |
138 | Correct | 0 ms | 344 KB | Output is correct |
139 | Correct | 0 ms | 344 KB | Output is correct |
140 | Correct | 0 ms | 348 KB | Output is correct |
141 | Correct | 0 ms | 348 KB | Output is correct |
142 | Correct | 0 ms | 348 KB | Output is correct |
143 | Correct | 0 ms | 348 KB | Output is correct |
144 | Correct | 1 ms | 604 KB | Output is correct |
145 | Correct | 1 ms | 604 KB | Output is correct |