이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<vv> vvv;
typedef pair<ll,ll> p;
typedef vector<p> vp;
typedef vector<vp> vvp;
typedef vector<vvp> vvvp;
typedef pair<ll, p> tri;
typedef vector<tri> vtri;
typedef vector<vtri> vvtri;
typedef vector<vvtri> vvvtri;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
const ll INF = 1e18;
const ll mod = 1e9 + 7;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll N, M;
cin >> N >> M;
vv graph(N);
for (ll i= 0; i < M; i++)
{
ll a, b;
cin >> a >> b;
graph[a-1].pb(b-1);
graph[b-1].pb(a-1);
}
v next((1ll << N));
for (ll i= 0; i < (1ll << N); i++)
{
for (ll j = 0; j < N; j++)
{
if (i & (1 << j))
{
for (ll x : graph[j]) next[i] |= (1 << x);
}
}
}
vvp stateGraph((1ll << N));
for (ll i = 0; i < (1 << N); i++)
{
for (ll j = 0; j < N; j++)
{
if (i & (1 << j))
stateGraph[i].eb(next[i ^ (1 << j)], j);
}
}
vb visited((1 << N), false);
ll start = (1 << N) - 1; ll end = 0;
queue<tri> dfs;
vp prev((1 << N));
dfs.emplace(start, p(-1, -1));
while (!dfs.empty())
{
auto top = dfs.front(); dfs.pop();
if (visited[top.f]) continue; visited[top.f] = true; prev[top.f] = top.s;
for (auto x : stateGraph[top.f]) dfs.emplace(x.f, p(top.f, x.s));
}
if (!visited[end])
{
cout << "NO\n";
return 0;
}
cout << "YES\n";
v strategy;
ll cur = end;
while (prev[cur].f != -1)
{
strategy.pb(prev[cur].s);
cur = prev[cur].f;
}
reverse(all(strategy));
cout << strategy.size() << "\n";
for (ll x : strategy) cout << x + 1 << " ";
cout << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
newspapers.cpp: In function 'int main()':
newspapers.cpp:71:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
71 | if (visited[top.f]) continue; visited[top.f] = true; prev[top.f] = top.s;
| ^~
newspapers.cpp:71:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
71 | if (visited[top.f]) continue; visited[top.f] = true; prev[top.f] = top.s;
| ^~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |