답안 #955450

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955450 2024-03-30T13:10:26 Z yoav_s Newspapers (CEOI21_newspapers) C++17
12 / 100
481 ms 295764 KB
#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;
}

Compilation message

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;
      |                                       ^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 2 ms 1116 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 1 ms 1116 KB Output is correct
27 Correct 3 ms 1884 KB Output is correct
28 Correct 3 ms 1884 KB Output is correct
29 Correct 3 ms 1884 KB Output is correct
30 Correct 4 ms 1884 KB Output is correct
31 Correct 6 ms 3676 KB Output is correct
32 Correct 5 ms 3676 KB Output is correct
33 Correct 5 ms 3676 KB Output is correct
34 Correct 5 ms 3676 KB Output is correct
35 Correct 11 ms 7516 KB Output is correct
36 Correct 10 ms 7636 KB Output is correct
37 Correct 10 ms 7512 KB Output is correct
38 Correct 10 ms 7516 KB Output is correct
39 Correct 22 ms 15708 KB Output is correct
40 Correct 21 ms 15704 KB Output is correct
41 Correct 25 ms 15700 KB Output is correct
42 Correct 22 ms 15708 KB Output is correct
43 Correct 47 ms 32864 KB Output is correct
44 Correct 45 ms 32852 KB Output is correct
45 Correct 45 ms 33112 KB Output is correct
46 Correct 44 ms 32852 KB Output is correct
47 Correct 88 ms 68708 KB Output is correct
48 Correct 102 ms 68728 KB Output is correct
49 Correct 87 ms 68944 KB Output is correct
50 Correct 87 ms 68948 KB Output is correct
51 Correct 180 ms 142960 KB Output is correct
52 Correct 182 ms 142920 KB Output is correct
53 Correct 178 ms 142932 KB Output is correct
54 Correct 195 ms 142964 KB Output is correct
55 Correct 394 ms 295680 KB Output is correct
56 Correct 393 ms 295764 KB Output is correct
57 Correct 371 ms 295760 KB Output is correct
58 Correct 368 ms 295748 KB Output is correct
59 Correct 436 ms 295764 KB Output is correct
60 Correct 411 ms 295764 KB Output is correct
61 Correct 388 ms 295728 KB Output is correct
62 Correct 392 ms 295760 KB Output is correct
63 Correct 452 ms 295764 KB Output is correct
64 Correct 481 ms 295760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Runtime error 2 ms 604 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 2 ms 1116 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 1 ms 1116 KB Output is correct
27 Correct 3 ms 1884 KB Output is correct
28 Correct 3 ms 1884 KB Output is correct
29 Correct 3 ms 1884 KB Output is correct
30 Correct 4 ms 1884 KB Output is correct
31 Correct 6 ms 3676 KB Output is correct
32 Correct 5 ms 3676 KB Output is correct
33 Correct 5 ms 3676 KB Output is correct
34 Correct 5 ms 3676 KB Output is correct
35 Correct 11 ms 7516 KB Output is correct
36 Correct 10 ms 7636 KB Output is correct
37 Correct 10 ms 7512 KB Output is correct
38 Correct 10 ms 7516 KB Output is correct
39 Correct 22 ms 15708 KB Output is correct
40 Correct 21 ms 15704 KB Output is correct
41 Correct 25 ms 15700 KB Output is correct
42 Correct 22 ms 15708 KB Output is correct
43 Correct 47 ms 32864 KB Output is correct
44 Correct 45 ms 32852 KB Output is correct
45 Correct 45 ms 33112 KB Output is correct
46 Correct 44 ms 32852 KB Output is correct
47 Correct 88 ms 68708 KB Output is correct
48 Correct 102 ms 68728 KB Output is correct
49 Correct 87 ms 68944 KB Output is correct
50 Correct 87 ms 68948 KB Output is correct
51 Correct 180 ms 142960 KB Output is correct
52 Correct 182 ms 142920 KB Output is correct
53 Correct 178 ms 142932 KB Output is correct
54 Correct 195 ms 142964 KB Output is correct
55 Correct 394 ms 295680 KB Output is correct
56 Correct 393 ms 295764 KB Output is correct
57 Correct 371 ms 295760 KB Output is correct
58 Correct 368 ms 295748 KB Output is correct
59 Correct 436 ms 295764 KB Output is correct
60 Correct 411 ms 295764 KB Output is correct
61 Correct 388 ms 295728 KB Output is correct
62 Correct 392 ms 295760 KB Output is correct
63 Correct 452 ms 295764 KB Output is correct
64 Correct 481 ms 295760 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 1 ms 344 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Runtime error 2 ms 604 KB Execution killed with signal 6
80 Halted 0 ms 0 KB -