Submission #812582

# Submission time Handle Problem Language Result Execution time Memory
812582 2023-08-07T09:25:54 Z ono_de206 Newspapers (CEOI21_newspapers) C++14
0 / 100
3 ms 7380 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// #define int long long
 
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T, typename U>
ostream & operator << (ostream &out, const pair<T, U> &c) {
	out << c.first << ' ' << c.second;
    return out;
}

template<typename T>
ostream & operator << (ostream &out, vector<T> &v) {
	const int sz = v.size();
	for (int i = 0; i < sz; i++) {
		if (i) out << ' ';
		out << v[i];
	}
    return out;
}

template<typename T>
istream & operator >> (istream &in, vector<T> &v) {
	for (T &x : v) in >> x;
    return in;
}


template<typename T>
void mxx(T &a, T b){if(b > a) a = b;}
template<typename T>
void mnn(T &a, T b){if(b < a) a = b;}

const int mxn = 21, MX = 3e5 + 10;
vector<int> g[MX];
int vis[MX], k[MX], lol[1 << mxn];
pair<int, int> dp[5 * mxn][1 << mxn];

bool dfs(int to, int fr) {
	vis[to] = 1;
	for(int x : g[to]) {
		if(x == fr) continue;
		if(vis[x] || dfs(x, to)) return true;
	}
	return false;
}

void go() {
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= m; i++) {
		int x, y; cin >> x >> y; x--; y--;
		g[x].pb(y); g[y].pb(x);
		k[x] |= (1 << y); k[y] |= (1 << x);
	}

	if(dfs(0, 0)) {
		cout << "NO\n";
		return;
	}

	if(n > 1) {
		cout << "YES\n" << n * 2 - 4 << '\n';
		for(int i = 2; i < n; i++) {
			cout << i << ' ';
		}
		for(int i = n - 1; i >= 2; i--) {
			cout << i << ' ';
		}
		cout << '\n';
		return;
	}

	for(int i = 0; i < (1 << n); i++) {
		for(int j = 0; j < n; j++) {
			if((i >> j) & 1) lol[i] |= k[j];
		}
	}

	for(int i = 0; i <= 2 * n; i++) {
		for(int j = 0; j < (1 << n); j++) {
			dp[i][j] = {-1, -1};
		}
	}
	dp[0][(1 << n) - 1] = {0, 0};
	for(int i = 0; i <= 2 * n; i++) {
		if(dp[i][0].ff != -1) {
			cout << "YES\n";
			int x = i, now = 0;
			cout << x << '\n';
			vector<int> ans;
			for(int p = 0; p < x; p++) {
				ans.pb(dp[x - p][now].ss + 1);
				now = dp[x - p][now].ff;
			}
			reverse(all(ans));
			cout << ans << '\n';
			return;
		}
		if(i == 2 * n) break;
		for(int j = 0; j < (1 << n); j++) {
			if(dp[i][j].ff == -1) continue;
			for(int k = 0; k < n; k++) {
				if(!((j >> k) & 1)) continue;
				dp[i + 1][lol[j ^ (1 << k)]] = {j, k};
			}
		}
	}
	cout << "NO\n";
}
 
signed main() {
	// #ifndef ONO
	// freopen("file.in", "r", stdin);
	// freopen("file.out", "w", stdout);
	// #endif
	fast;
	int t = 1;
	// cin >> t;
	while(t--) {
		go();
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7380 KB Output is correct
2 Incorrect 3 ms 7380 KB Integer parameter [name=k] equals to 0, violates the range [1, 10]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7380 KB Output is correct
2 Incorrect 3 ms 7380 KB Integer parameter [name=k] equals to 0, violates the range [1, 10]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7380 KB Output is correct
2 Incorrect 3 ms 7380 KB Integer parameter [name=k] equals to 0, violates the range [1, 10]
3 Halted 0 ms 0 KB -