제출 #955450

#제출 시각아이디문제언어결과실행 시간메모리
955450yoav_sNewspapers (CEOI21_newspapers)C++17
12 / 100
481 ms295764 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...