# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
953099 | Sacharlemagne | Newspapers (CEOI21_newspapers) | C++17 | 336 ms | 524288 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <vector>
#include <iostream>
#include <queue>
using namespace std;
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n,m,a,b; cin >> n >> m;
vector<vector<int>> adj(n);
while (m--) {
cin >> a >> b;
adj[--a].push_back(--b);
adj[b].push_back(a);
}
vector<pair<int,int>> par(1 << n);
queue<int> q; q.push((1<<n)-1);
vector<int> dist(1<<n, 100); dist[(1<<n)-1] = 0;
while (!q.empty()) {
int node = q.front(); q.pop();
int i = node;
vector<int> access(n);
for (int j = 0; j<n; ++j) {
if (!(i & (1 << j))) continue;
for (int u : adj[j]) ++access[u];
}
for (int on = 0; on<n; ++on) {
int nei = 0;
if (i && (1 << on)) {
for (int u : adj[on]) {
--access[u];
}
}
for (int j = 0; j<n; ++j) if (access[j]) nei += (1 << j);
if (i && (1 << on)) for (int u : adj[on]) ++access[u];
if (nei == 0) {
par[nei] = {node, on};
vector<int> ans; ans.reserve(dist[node]+1);
while (nei != ((1 << n)-1)) {
ans.push_back(par[nei].second);
nei = par[nei].first;
}
cout << "YES\n";
cout << ans.size() << "\n";
for (int i = ans.size()-1; i>=0;--i) cout << ans[i]+1 << ' ';
return 0;
}
if (dist[nei] == 100) {
par[nei] = {node, on};
dist[nei] = dist[node]+1;
q.push(nei);
}
}
}
cout << "NO";
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |