Submission #519310

# Submission time Handle Problem Language Result Execution time Memory
519310 2022-01-26T07:47:09 Z Keshi Newspapers (CEOI21_newspapers) C++17
0 / 100
0 ms 204 KB
//In the name of God
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll maxn = 2e6 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()

ll pw(ll a, ll b){
	ll c = 1;
	while(b){
		if(b & 1) c = c * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return c;
}

int n, m, g[maxn], d[maxn], p[maxn], pp[maxn];
bool vis[maxn];
queue<int> q;

int get(int x){
	int y = 0;
	for(int i = 0; i < n; i++){
		if((x >> i) & 1) y |= g[i];
	}
	return y;
}

int main(){
	fast_io;

	cin >> n >> m;
	if(m != n - 1){
		cout << "NO\n";
		return 0;
	}
	bool sub2 = 1;
	for(int i = 0; i < m; i++){
		int v, u;
		cin >> v >> u;
		v--;
		u--;
		if(abs(v - u) != 1) sub2 = 0;
		g[v] |= (1 << u);
		g[u] |= (1 << v);
	}
	if(sub2){
		cout << "YES\n";
		cout << 2 * n - 4 << "\n";
		for(int i = 2; i < n; i++){
			cout << i << " ";
		}
		for(int i = n - 1; i > 1; i--){
			cout << i << " ";
		}
		return 0;
	}
	p[(1 << n) - 1] = -1;
	vis[(1 << n) - 1] = 1;
	q.push((1 << n) - 1);
	while(!q.empty()){
		int v = q.front();
		q.pop();
		for(int i = 0; i < n; i++){
			int u = get(v & (~(1 << i)));
			if(!vis[u]){
				vis[u] = 1;
				d[u] = d[v] + 1;
				p[u] = v;
				pp[u] = i;
				q.push(u);
			}
		}
	}
	if(!vis[0]){
		cout << "NO\n";
		return 0;
	}
	cout << "YES\n";
	cout << d[0] << "\n";
	int v = 0;
	vector<int> vec;
	while(p[v] != -1){
		vec.pb(pp[v]);
		v = p[v];
	}
	reverse(all(vec));
	for(int i : vec){
		cout << i + 1 << " ";
	}

	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Integer parameter [name=k] equals to -2, violates the range [1, 5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Integer parameter [name=k] equals to -2, violates the range [1, 5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Integer parameter [name=k] equals to -2, violates the range [1, 5]
2 Halted 0 ms 0 KB -