Submission #659765

# Submission time Handle Problem Language Result Execution time Memory
659765 2022-11-19T08:55:14 Z Sohsoh84 Newspapers (CEOI21_newspapers) C++17
75 / 100
2 ms 468 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> 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 = 1e3 + 10;

int n, m, dist[MAXN], par[MAXN], D[MAXN];
vector<int> adj[MAXN], diam, ans;

void dfs(int v) {
	dist[v] = dist[par[v]] + 1;
	D[v] = 1;
	for (int u : adj[v]) {
		if (u != par[v]) {
			par[u] = v;
			dfs(u);
			D[v] = max(D[v], D[u] + 1);
		}
	}
}

inline void add(int v) {
	int m = ans.size();
	if (m >= 2 && ans[m - 1] == v && ans[m - 2] == v) {
		ans.pop_back();
		ans.pop_back();
	}
	
	ans.push_back(v);
}

inline void dojob() {
	int m = diam.size();
	int i = 0;
	for (i = 0; i < m - 1; i++) {
		int v = diam[i];	
		if (i > 0) add(v);
		for (int u : adj[v]) {
			if (u == par[v] || u == diam[i + 1]) continue;
			if (D[u] >= 3) {
				cout << "NO" << endl;
				exit(0);
			}
			
			add(v);
			add(u);
		}

		add(v);
		add(diam[i + 1]);
	}

	add(diam[i]);
	add(diam[i]); // check
}

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 <= m; i++) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	dfs(1);
	int v = max_element(dist, dist + MAXN) - dist;
	
	memset(par, 0, sizeof par);
	memset(dist, 0, sizeof dist);
	dfs(v);
	v = max_element(dist, dist + MAXN) - dist;
	while (v) {
		diam.push_back(v);
		v = par[v];
	}

	reverse(all(diam));
	dojob();
	if (ans.size() % 2 == 0) ans.push_back(1);
	dojob();

	cout << "YES" << endl << ans.size() << endl;
	for (int e : ans) cout << e << sep;
	cout << endl;
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
3 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
4 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
5 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
6 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
7 Correct 0 ms 340 KB Output is correct
8 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
9 Correct 0 ms 340 KB Output is correct
10 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
11 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
12 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
13 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
14 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
15 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
16 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
17 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
18 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
19 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
20 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
21 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
22 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
23 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
24 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
25 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
26 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
27 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
28 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
29 Correct 0 ms 340 KB Output is correct
30 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
31 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
32 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
33 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
34 Correct 0 ms 340 KB Output is correct
35 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
36 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
37 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
38 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
39 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
40 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
41 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
42 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
43 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
44 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
45 Correct 0 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
49 Correct 0 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
55 Correct 0 ms 340 KB Output is correct
56 Correct 0 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 0 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
3 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
4 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
5 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
6 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
7 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
8 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
9 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
10 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
11 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
12 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
13 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
14 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
15 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
16 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
17 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
18 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
19 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
20 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
3 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
4 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
5 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
6 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
7 Correct 0 ms 340 KB Output is correct
8 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
9 Correct 0 ms 340 KB Output is correct
10 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
11 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
12 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
13 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
14 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
15 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
16 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
17 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
18 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
19 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
20 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
21 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
22 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
23 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
24 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
25 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
26 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
27 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
28 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
29 Correct 0 ms 340 KB Output is correct
30 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
31 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
32 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
33 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
34 Correct 0 ms 340 KB Output is correct
35 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
36 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
37 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
38 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
39 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
40 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
41 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
42 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
43 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
44 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
45 Correct 0 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
49 Correct 0 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
55 Correct 0 ms 340 KB Output is correct
56 Correct 0 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 0 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 0 ms 340 KB Output is correct
66 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
67 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
68 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
69 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
70 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
71 Correct 0 ms 340 KB Output is correct
72 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
73 Correct 1 ms 340 KB Output is correct
74 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
75 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
76 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
77 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
78 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 1 ms 340 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 1 ms 340 KB Output is correct
86 Correct 1 ms 340 KB Output is correct
87 Correct 1 ms 340 KB Output is correct
88 Correct 1 ms 340 KB Output is correct
89 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
90 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
91 Partially correct 1 ms 372 KB Provide a successful but not optimal strategy.
92 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
93 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
94 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
95 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
96 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
97 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
98 Partially correct 2 ms 340 KB Provide a successful but not optimal strategy.
99 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
100 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
101 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
102 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
103 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
104 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
105 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
106 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
107 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
108 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
109 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
110 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
111 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
112 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
113 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
114 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
115 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
116 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
117 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
118 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
119 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
120 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
121 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
122 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
123 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
124 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
125 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
126 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
127 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
128 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
129 Correct 1 ms 340 KB Output is correct
130 Correct 1 ms 340 KB Output is correct
131 Correct 1 ms 340 KB Output is correct
132 Correct 1 ms 340 KB Output is correct
133 Correct 1 ms 340 KB Output is correct
134 Correct 0 ms 340 KB Output is correct
135 Correct 1 ms 340 KB Output is correct
136 Correct 0 ms 340 KB Output is correct
137 Correct 0 ms 340 KB Output is correct
138 Correct 0 ms 340 KB Output is correct
139 Correct 0 ms 340 KB Output is correct
140 Correct 0 ms 340 KB Output is correct
141 Correct 0 ms 340 KB Output is correct
142 Correct 0 ms 340 KB Output is correct
143 Correct 0 ms 340 KB Output is correct
144 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
145 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.