Submission #659749

# Submission time Handle Problem Language Result Execution time Memory
659749 2022-11-19T08:21:19 Z Sohsoh84 Newspapers (CEOI21_newspapers) C++17
6 / 100
1 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 dojob() {
	int m = diam.size();
	int i = 0;
	for (i = 0; i < m - 1; i += 2) {
		int v = diam[i];
		for (int u : adj[v]) {
			if (u == par[v] || u == diam[i + 1]) continue;
			if (D[u] >= 3) {
				cout << "NO" << endl;
				exit(0);
			}
			
			ans.push_back(v);
			ans.push_back(u);
		}

		ans.push_back(v);
		ans.push_back(diam[i + 1]);
	}

	if (i == m - 1) ans.push_back(diam[i]);
}

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;
	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 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
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 0 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 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 Incorrect 0 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
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 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 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
8 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
9 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
10 Partially correct 1 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 0 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 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
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 0 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 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 Incorrect 0 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -