Submission #576554

# Submission time Handle Problem Language Result Execution time Memory
576554 2022-06-13T07:41:34 Z temporary_juggernaut Newspapers (CEOI21_newspapers) C++14
8 / 100
1 ms 468 KB
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef juggernaut
    #define printl(args...)printf(args)
#else
    #define printl(args...)((void)0)
#endif
vector<int>g[1005];
int depth[1005];
bool vis[1005];
int flag;
int dfs(int v,int p){
	depth[v]=0;
	int x=v;
	for(int to:g[v])if(to!=p){
		int y=dfs(to,v);
		if(depth[to]+1>depth[v]){
			depth[v]=depth[to]+1;
			x=y;
		}
	}
	return x;
}
void chk(int v){
	for(int to:g[v])if(!vis[to]){
		puts("NO");
		exit(0);
	}
}
int main(){
	int n;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int m;
	cin>>n>>m;
	if(m>=n)return puts("NO"),0;
	while(m--){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int root=dfs(1,1);
	root=dfs(root,1);
	for(int i=1;i<=n;i++)if(g[i].size()>2)flag++;
	while(!vis[root]){
		vis[root]=1;
		for(int to:g[root])if(depth[to]+1==depth[root]){
			root=to;
			break;
		}
	}
	if(flag>1)for(int i=1;i<=n;i++)if(!vis[i])chk(i);
	if(n==1){
		puts("YES\n1\n1");
		return 0;
	}else if(n==2||n==3){
		puts("YES\n2\n2 2");
		return 0;
	}
	vector<int>vec;
	if(n&1){
		for(int i=2;i<n;i++)vec.push_back(i);
		for(int i=2;i<n;i++)vec.push_back(i);
	}else{
		for(int i=2;i<n;i++)vec.push_back(i);
		for(int i=n-1;i>1;i--)vec.push_back(i);
	}
	printf("YES\n%d\n",int(vec.size()));
	for(int to:vec)printf("%d ",to);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Partially correct 0 ms 340 KB Failed to provide a successful strategy.
6 Incorrect 0 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Partially correct 0 ms 340 KB Failed to provide a successful strategy.
6 Incorrect 0 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -