답안 #592091

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
592091 2022-07-08T13:37:47 Z SeDunion Newspapers (CEOI21_newspapers) C++17
12 / 100
499 ms 214640 KB
#include <iostream>
#include <cassert>
#include <iomanip>
#include <algorithm>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#ifndef LOCAL
	#include <bits/stdc++.h>
	#define cerr if(false)cerr
#endif
 
using namespace std;
using ll = long long;
 
const int N = 2e6 + 66;
 
vector<pair<int,int>>G[N];
pair<int,int>p[N];
 
int d[N];
 
int ea[N], eb[N];
 
int cnt[N], mp[33][33];
 
int cycle;
vector<int>g[N];
 
int used[N];
 
void dfs(int v, int p = -1) {
	used[v] = 1;
	for (int to : g[v]) if (to != p) {
		if (used[to] == 1) cycle = 1;
		if (used[to] == 0) dfs(to, v);
	}
	used[v] = 2;
}
 
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	for (int i = 0 ; i < m ; ++ i) cin >> ea[i] >> eb[i];
	for (int i = 0 ; i < m ; ++ i) ea[i]--, eb[i]--, mp[ea[i]][eb[i]] = mp[eb[i]][ea[i]] = 1, g[ea[i]].emplace_back(eb[i]), g[eb[i]].emplace_back(ea[i]);
	for (int i = 1 ; i <= n ; ++ i) if (!used[i]) {
		dfs(i);
	}
	if (cycle) {
		cout << "NO";
		return 0;
	}
	for (int mask = 1 ; mask < (1 << n) ; ++ mask) {
		for (int i = 0 ; i < n ; ++ i) cnt[i] = 0;
		int nms = 0;
			for (int j = 0 ; j < m ; ++ j) {
				int x = ea[j], y = eb[j];
				if (mask >> y & 1) cnt[x]++, nms |= (1 << x);
				if (mask >> x & 1) cnt[y]++, nms |= (1 << y);
			}
		for (int i = 0 ; i < n ; ++ i) if (mask >> i & 1) {
			int gms = nms;
			for (int j : g[i]) {
				if (cnt[j] == 1) gms ^= (1 << j);
			}
			G[gms].emplace_back(mask, i + 1);
		}
	}
	for (int i = 0 ; i < (1 << n) ; ++ i) d[i] = -1;
	d[0] = 0;
	queue<int>q;
	q.push(0);
	while (q.size()) {
		int v = q.front(); q.pop();
		for (auto [to, w] : G[v]) if (d[to] == -1) {
			p[to] = {v, w};
			d[to] = d[v] + 1;
			q.push(to);
		}
	}
	if (d[(1 << n) - 1] == -1) {
		cout << "NO";
		return 0;
	}
	cout << "YES\n";
	cout << d[(1 << n) - 1] << "\n";
	int x = (1 << n) - 1;
	while (x) {
		cout << p[x].second << " ";
		x = p[x].first;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 94252 KB Output is correct
2 Correct 51 ms 94252 KB Output is correct
3 Correct 44 ms 94296 KB Output is correct
4 Correct 44 ms 94384 KB Output is correct
5 Correct 44 ms 94252 KB Output is correct
6 Correct 49 ms 94292 KB Output is correct
7 Correct 46 ms 94272 KB Output is correct
8 Correct 43 ms 94308 KB Output is correct
9 Correct 44 ms 94260 KB Output is correct
10 Correct 43 ms 94224 KB Output is correct
11 Correct 50 ms 94192 KB Output is correct
12 Correct 47 ms 94260 KB Output is correct
13 Correct 44 ms 94256 KB Output is correct
14 Correct 44 ms 94212 KB Output is correct
15 Correct 43 ms 94284 KB Output is correct
16 Correct 51 ms 94392 KB Output is correct
17 Correct 43 ms 94452 KB Output is correct
18 Correct 43 ms 94368 KB Output is correct
19 Correct 46 ms 94340 KB Output is correct
20 Correct 45 ms 94412 KB Output is correct
21 Correct 45 ms 94352 KB Output is correct
22 Correct 44 ms 94456 KB Output is correct
23 Correct 44 ms 94528 KB Output is correct
24 Correct 43 ms 94512 KB Output is correct
25 Correct 45 ms 94540 KB Output is correct
26 Correct 47 ms 94644 KB Output is correct
27 Correct 48 ms 95060 KB Output is correct
28 Correct 46 ms 94920 KB Output is correct
29 Correct 46 ms 95020 KB Output is correct
30 Correct 46 ms 94932 KB Output is correct
31 Correct 48 ms 95920 KB Output is correct
32 Correct 50 ms 95816 KB Output is correct
33 Correct 50 ms 95908 KB Output is correct
34 Correct 50 ms 95788 KB Output is correct
35 Correct 54 ms 97420 KB Output is correct
36 Correct 55 ms 97612 KB Output is correct
37 Correct 53 ms 97600 KB Output is correct
38 Correct 57 ms 97480 KB Output is correct
39 Correct 67 ms 101092 KB Output is correct
40 Correct 70 ms 101116 KB Output is correct
41 Correct 62 ms 100756 KB Output is correct
42 Correct 64 ms 100840 KB Output is correct
43 Correct 86 ms 107892 KB Output is correct
44 Correct 84 ms 107884 KB Output is correct
45 Correct 88 ms 107152 KB Output is correct
46 Correct 85 ms 107984 KB Output is correct
47 Correct 122 ms 121020 KB Output is correct
48 Correct 132 ms 122380 KB Output is correct
49 Correct 123 ms 121288 KB Output is correct
50 Correct 132 ms 121952 KB Output is correct
51 Correct 222 ms 150632 KB Output is correct
52 Correct 200 ms 148412 KB Output is correct
53 Correct 228 ms 149540 KB Output is correct
54 Correct 229 ms 147284 KB Output is correct
55 Correct 399 ms 207336 KB Output is correct
56 Correct 361 ms 197224 KB Output is correct
57 Correct 499 ms 214640 KB Output is correct
58 Correct 409 ms 205536 KB Output is correct
59 Correct 44 ms 94220 KB Output is correct
60 Correct 43 ms 94220 KB Output is correct
61 Correct 44 ms 94284 KB Output is correct
62 Correct 44 ms 94160 KB Output is correct
63 Correct 49 ms 94284 KB Output is correct
64 Correct 48 ms 94160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 94272 KB Output is correct
2 Correct 43 ms 94168 KB Output is correct
3 Correct 43 ms 94196 KB Output is correct
4 Correct 47 ms 94292 KB Output is correct
5 Correct 48 ms 94188 KB Output is correct
6 Correct 56 ms 94324 KB Output is correct
7 Correct 46 ms 94288 KB Output is correct
8 Correct 44 ms 94188 KB Output is correct
9 Correct 45 ms 94204 KB Output is correct
10 Correct 45 ms 94372 KB Output is correct
11 Runtime error 113 ms 191360 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 94252 KB Output is correct
2 Correct 51 ms 94252 KB Output is correct
3 Correct 44 ms 94296 KB Output is correct
4 Correct 44 ms 94384 KB Output is correct
5 Correct 44 ms 94252 KB Output is correct
6 Correct 49 ms 94292 KB Output is correct
7 Correct 46 ms 94272 KB Output is correct
8 Correct 43 ms 94308 KB Output is correct
9 Correct 44 ms 94260 KB Output is correct
10 Correct 43 ms 94224 KB Output is correct
11 Correct 50 ms 94192 KB Output is correct
12 Correct 47 ms 94260 KB Output is correct
13 Correct 44 ms 94256 KB Output is correct
14 Correct 44 ms 94212 KB Output is correct
15 Correct 43 ms 94284 KB Output is correct
16 Correct 51 ms 94392 KB Output is correct
17 Correct 43 ms 94452 KB Output is correct
18 Correct 43 ms 94368 KB Output is correct
19 Correct 46 ms 94340 KB Output is correct
20 Correct 45 ms 94412 KB Output is correct
21 Correct 45 ms 94352 KB Output is correct
22 Correct 44 ms 94456 KB Output is correct
23 Correct 44 ms 94528 KB Output is correct
24 Correct 43 ms 94512 KB Output is correct
25 Correct 45 ms 94540 KB Output is correct
26 Correct 47 ms 94644 KB Output is correct
27 Correct 48 ms 95060 KB Output is correct
28 Correct 46 ms 94920 KB Output is correct
29 Correct 46 ms 95020 KB Output is correct
30 Correct 46 ms 94932 KB Output is correct
31 Correct 48 ms 95920 KB Output is correct
32 Correct 50 ms 95816 KB Output is correct
33 Correct 50 ms 95908 KB Output is correct
34 Correct 50 ms 95788 KB Output is correct
35 Correct 54 ms 97420 KB Output is correct
36 Correct 55 ms 97612 KB Output is correct
37 Correct 53 ms 97600 KB Output is correct
38 Correct 57 ms 97480 KB Output is correct
39 Correct 67 ms 101092 KB Output is correct
40 Correct 70 ms 101116 KB Output is correct
41 Correct 62 ms 100756 KB Output is correct
42 Correct 64 ms 100840 KB Output is correct
43 Correct 86 ms 107892 KB Output is correct
44 Correct 84 ms 107884 KB Output is correct
45 Correct 88 ms 107152 KB Output is correct
46 Correct 85 ms 107984 KB Output is correct
47 Correct 122 ms 121020 KB Output is correct
48 Correct 132 ms 122380 KB Output is correct
49 Correct 123 ms 121288 KB Output is correct
50 Correct 132 ms 121952 KB Output is correct
51 Correct 222 ms 150632 KB Output is correct
52 Correct 200 ms 148412 KB Output is correct
53 Correct 228 ms 149540 KB Output is correct
54 Correct 229 ms 147284 KB Output is correct
55 Correct 399 ms 207336 KB Output is correct
56 Correct 361 ms 197224 KB Output is correct
57 Correct 499 ms 214640 KB Output is correct
58 Correct 409 ms 205536 KB Output is correct
59 Correct 44 ms 94220 KB Output is correct
60 Correct 43 ms 94220 KB Output is correct
61 Correct 44 ms 94284 KB Output is correct
62 Correct 44 ms 94160 KB Output is correct
63 Correct 49 ms 94284 KB Output is correct
64 Correct 48 ms 94160 KB Output is correct
65 Correct 48 ms 94400 KB Output is correct
66 Correct 46 ms 94252 KB Output is correct
67 Correct 43 ms 94280 KB Output is correct
68 Correct 43 ms 94272 KB Output is correct
69 Correct 43 ms 94292 KB Output is correct
70 Correct 43 ms 94232 KB Output is correct
71 Correct 43 ms 94172 KB Output is correct
72 Correct 44 ms 94216 KB Output is correct
73 Correct 50 ms 94288 KB Output is correct
74 Correct 45 ms 94328 KB Output is correct
75 Correct 43 ms 94260 KB Output is correct
76 Correct 45 ms 94272 KB Output is correct
77 Correct 44 ms 94256 KB Output is correct
78 Correct 43 ms 94284 KB Output is correct
79 Runtime error 113 ms 191188 KB Execution killed with signal 11
80 Halted 0 ms 0 KB -