Submission #400967

# Submission time Handle Problem Language Result Execution time Memory
400967 2021-05-08T22:40:56 Z 534351 From Hacks to Snitches (BOI21_watchmen) C++17
25 / 100
5993 ms 97876 KB
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

const int MAXN = 250013;
const int MAXC = 2813;
const int INF = 1e9 + 7;
const int DELTA = 125;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N, M, K, B;
vi edge[MAXN];
int ban[MAXN], md[MAXN], id[MAXN], dist[MAXN], cc[MAXN];
bool hasfriend[MAXN];
set<pii> q;

int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N >> M;
    FOR(i, 0, M)
    {
        int u, v;
        cin >> u >> v; u--; v--;
        edge[u].PB(v);
        edge[v].PB(u);
    }
    FOR(i, 0, N)
    {
        edge[i].PB(i);
        cc[i] = -1;
    }
    cin >> K;
    FOR(i, 0, K)
    {
        int c; cin >> c;
        vi s(c);
        FOR(j, 0, c)
        {
            cin >> s[j]; s[j]--;
            id[s[j]] = B; B++;
            ban[s[j]] = j;
            cc[s[j]] = i;
        }
        md[i] = c;
    }
    FOR(i, 0, N)
    {
        for (int u : edge[i])
        {
            if (cc[u] == -1) hasfriend[i] = true;
        }
    }
    fill(dist, dist + N, INF);
    dist[0] = 0;
    q.insert({0, 0});
    while(!q.empty())
    {
        int d = q.begin() -> fi, u = q.begin() -> se; q.erase(q.begin());
        if (u == N - 1) break;
        // cerr << d << ' ' << u << endl;
        // bool ok = false;
        // for (int v : edge[u])
        // {
        //     if (!seen[v][0]) ok = true;
        //     //make sure there's one univisited neighbor
        // }
        // if (!ok) continue;
        for (int v : edge[u])
        {
            if (cc[v] != -1)
            {
                int mx = 7;
                if (cc[u] != -1)
                {
                    mx = 2;
                    if (hasfriend[u] && v == u) mx = 3;
                }
                FOR(j, 1, mx)
                {
                    // cerr << u << ' ' << v << ' ' << (d + j) << endl;
                    int m = md[cc[v]];
                    if ((d + j) % m == ban[v]) continue;
                    if (cc[u] == cc[v] && (d + j) % m == ban[u] && (d + j - 1) % m == ban[v]) continue;
                    if (dist[v] > d + j)
                    {
                        dist[v] = d + j;
                    }
                    if (d + j - dist[v] >= DELTA) continue;
                    q.insert({d + j, v});
                }
            }
            else
            {
                if (dist[v] > d + 1)
                {
                    dist[v] = d + 1;
                    q.insert({d + 1, v});
                }
            }
        }
    }
    if (dist[N - 1] >= INF)
    {
        cout << "impossible\n";
        return 0;
    }
    cout << dist[N - 1] << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 35 ms 7116 KB Output is correct
2 Correct 63 ms 10744 KB Output is correct
3 Correct 66 ms 10736 KB Output is correct
4 Correct 253 ms 10724 KB Output is correct
5 Correct 6 ms 6220 KB Output is correct
6 Correct 69 ms 10692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 7144 KB Output is correct
2 Correct 65 ms 10720 KB Output is correct
3 Correct 70 ms 10796 KB Output is correct
4 Correct 287 ms 10720 KB Output is correct
5 Correct 6 ms 6220 KB Output is correct
6 Correct 70 ms 10748 KB Output is correct
7 Correct 72 ms 10656 KB Output is correct
8 Correct 66 ms 10612 KB Output is correct
9 Correct 84 ms 10616 KB Output is correct
10 Correct 178 ms 10964 KB Output is correct
11 Correct 104 ms 10656 KB Output is correct
12 Correct 74 ms 10764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 7144 KB Output is correct
2 Correct 65 ms 10720 KB Output is correct
3 Correct 70 ms 10796 KB Output is correct
4 Correct 287 ms 10720 KB Output is correct
5 Correct 6 ms 6220 KB Output is correct
6 Correct 70 ms 10748 KB Output is correct
7 Correct 72 ms 10656 KB Output is correct
8 Correct 66 ms 10612 KB Output is correct
9 Correct 84 ms 10616 KB Output is correct
10 Correct 178 ms 10964 KB Output is correct
11 Correct 104 ms 10656 KB Output is correct
12 Correct 74 ms 10764 KB Output is correct
13 Correct 36 ms 7072 KB Output is correct
14 Correct 63 ms 10648 KB Output is correct
15 Correct 83 ms 10820 KB Output is correct
16 Correct 250 ms 10612 KB Output is correct
17 Correct 7 ms 6228 KB Output is correct
18 Correct 70 ms 10696 KB Output is correct
19 Correct 65 ms 10692 KB Output is correct
20 Correct 76 ms 10676 KB Output is correct
21 Correct 64 ms 10600 KB Output is correct
22 Correct 166 ms 10840 KB Output is correct
23 Correct 102 ms 10692 KB Output is correct
24 Correct 67 ms 10792 KB Output is correct
25 Correct 1597 ms 52460 KB Output is correct
26 Correct 1504 ms 59480 KB Output is correct
27 Correct 1456 ms 52432 KB Output is correct
28 Correct 1099 ms 57656 KB Output is correct
29 Correct 5134 ms 49304 KB Output is correct
30 Correct 5532 ms 50324 KB Output is correct
31 Correct 1679 ms 97592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 7144 KB Output is correct
2 Correct 65 ms 10720 KB Output is correct
3 Correct 70 ms 10796 KB Output is correct
4 Correct 287 ms 10720 KB Output is correct
5 Correct 6 ms 6220 KB Output is correct
6 Correct 70 ms 10748 KB Output is correct
7 Correct 72 ms 10656 KB Output is correct
8 Correct 66 ms 10612 KB Output is correct
9 Correct 84 ms 10616 KB Output is correct
10 Correct 178 ms 10964 KB Output is correct
11 Correct 104 ms 10656 KB Output is correct
12 Correct 74 ms 10764 KB Output is correct
13 Correct 36 ms 7072 KB Output is correct
14 Correct 63 ms 10648 KB Output is correct
15 Correct 83 ms 10820 KB Output is correct
16 Correct 250 ms 10612 KB Output is correct
17 Correct 7 ms 6228 KB Output is correct
18 Correct 70 ms 10696 KB Output is correct
19 Correct 65 ms 10692 KB Output is correct
20 Correct 76 ms 10676 KB Output is correct
21 Correct 64 ms 10600 KB Output is correct
22 Correct 166 ms 10840 KB Output is correct
23 Correct 102 ms 10692 KB Output is correct
24 Correct 67 ms 10792 KB Output is correct
25 Correct 1597 ms 52460 KB Output is correct
26 Correct 1504 ms 59480 KB Output is correct
27 Correct 1456 ms 52432 KB Output is correct
28 Correct 1099 ms 57656 KB Output is correct
29 Correct 5134 ms 49304 KB Output is correct
30 Correct 5532 ms 50324 KB Output is correct
31 Correct 1679 ms 97592 KB Output is correct
32 Correct 35 ms 7716 KB Output is correct
33 Correct 83 ms 11960 KB Output is correct
34 Correct 77 ms 11864 KB Output is correct
35 Correct 245 ms 11872 KB Output is correct
36 Correct 8 ms 6220 KB Output is correct
37 Correct 82 ms 11928 KB Output is correct
38 Correct 69 ms 11896 KB Output is correct
39 Correct 76 ms 11804 KB Output is correct
40 Correct 70 ms 11656 KB Output is correct
41 Correct 164 ms 12008 KB Output is correct
42 Correct 107 ms 11844 KB Output is correct
43 Correct 73 ms 12020 KB Output is correct
44 Correct 1647 ms 90808 KB Output is correct
45 Correct 1524 ms 97876 KB Output is correct
46 Correct 1496 ms 91012 KB Output is correct
47 Correct 1188 ms 96236 KB Output is correct
48 Correct 5250 ms 88044 KB Output is correct
49 Correct 5993 ms 88584 KB Output is correct
50 Correct 1737 ms 97644 KB Output is correct
51 Incorrect 1786 ms 91708 KB Output isn't correct
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 7116 KB Output is correct
2 Correct 63 ms 10744 KB Output is correct
3 Correct 66 ms 10736 KB Output is correct
4 Correct 253 ms 10724 KB Output is correct
5 Correct 6 ms 6220 KB Output is correct
6 Correct 69 ms 10692 KB Output is correct
7 Correct 35 ms 7144 KB Output is correct
8 Correct 65 ms 10720 KB Output is correct
9 Correct 70 ms 10796 KB Output is correct
10 Correct 287 ms 10720 KB Output is correct
11 Correct 6 ms 6220 KB Output is correct
12 Correct 70 ms 10748 KB Output is correct
13 Correct 72 ms 10656 KB Output is correct
14 Correct 66 ms 10612 KB Output is correct
15 Correct 84 ms 10616 KB Output is correct
16 Correct 178 ms 10964 KB Output is correct
17 Correct 104 ms 10656 KB Output is correct
18 Correct 74 ms 10764 KB Output is correct
19 Correct 4 ms 6220 KB Output is correct
20 Correct 4 ms 6220 KB Output is correct
21 Correct 5 ms 6220 KB Output is correct
22 Correct 43 ms 7116 KB Output is correct
23 Correct 81 ms 10748 KB Output is correct
24 Correct 67 ms 10744 KB Output is correct
25 Correct 249 ms 10728 KB Output is correct
26 Correct 6 ms 6220 KB Output is correct
27 Correct 82 ms 10836 KB Output is correct
28 Correct 65 ms 10676 KB Output is correct
29 Correct 65 ms 10660 KB Output is correct
30 Correct 62 ms 10492 KB Output is correct
31 Correct 165 ms 10844 KB Output is correct
32 Correct 139 ms 10756 KB Output is correct
33 Correct 67 ms 10692 KB Output is correct
34 Incorrect 1844 ms 52744 KB Output isn't correct
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 7116 KB Output is correct
2 Correct 63 ms 10744 KB Output is correct
3 Correct 66 ms 10736 KB Output is correct
4 Correct 253 ms 10724 KB Output is correct
5 Correct 6 ms 6220 KB Output is correct
6 Correct 69 ms 10692 KB Output is correct
7 Correct 35 ms 7144 KB Output is correct
8 Correct 65 ms 10720 KB Output is correct
9 Correct 70 ms 10796 KB Output is correct
10 Correct 287 ms 10720 KB Output is correct
11 Correct 6 ms 6220 KB Output is correct
12 Correct 70 ms 10748 KB Output is correct
13 Correct 72 ms 10656 KB Output is correct
14 Correct 66 ms 10612 KB Output is correct
15 Correct 84 ms 10616 KB Output is correct
16 Correct 178 ms 10964 KB Output is correct
17 Correct 104 ms 10656 KB Output is correct
18 Correct 74 ms 10764 KB Output is correct
19 Correct 36 ms 7072 KB Output is correct
20 Correct 63 ms 10648 KB Output is correct
21 Correct 83 ms 10820 KB Output is correct
22 Correct 250 ms 10612 KB Output is correct
23 Correct 7 ms 6228 KB Output is correct
24 Correct 70 ms 10696 KB Output is correct
25 Correct 65 ms 10692 KB Output is correct
26 Correct 76 ms 10676 KB Output is correct
27 Correct 64 ms 10600 KB Output is correct
28 Correct 166 ms 10840 KB Output is correct
29 Correct 102 ms 10692 KB Output is correct
30 Correct 67 ms 10792 KB Output is correct
31 Correct 1597 ms 52460 KB Output is correct
32 Correct 1504 ms 59480 KB Output is correct
33 Correct 1456 ms 52432 KB Output is correct
34 Correct 1099 ms 57656 KB Output is correct
35 Correct 5134 ms 49304 KB Output is correct
36 Correct 5532 ms 50324 KB Output is correct
37 Correct 1679 ms 97592 KB Output is correct
38 Correct 4 ms 6220 KB Output is correct
39 Correct 4 ms 6220 KB Output is correct
40 Correct 5 ms 6220 KB Output is correct
41 Correct 43 ms 7116 KB Output is correct
42 Correct 81 ms 10748 KB Output is correct
43 Correct 67 ms 10744 KB Output is correct
44 Correct 249 ms 10728 KB Output is correct
45 Correct 6 ms 6220 KB Output is correct
46 Correct 82 ms 10836 KB Output is correct
47 Correct 65 ms 10676 KB Output is correct
48 Correct 65 ms 10660 KB Output is correct
49 Correct 62 ms 10492 KB Output is correct
50 Correct 165 ms 10844 KB Output is correct
51 Correct 139 ms 10756 KB Output is correct
52 Correct 67 ms 10692 KB Output is correct
53 Incorrect 1844 ms 52744 KB Output isn't correct
54 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 7116 KB Output is correct
2 Correct 63 ms 10744 KB Output is correct
3 Correct 66 ms 10736 KB Output is correct
4 Correct 253 ms 10724 KB Output is correct
5 Correct 6 ms 6220 KB Output is correct
6 Correct 69 ms 10692 KB Output is correct
7 Correct 35 ms 7144 KB Output is correct
8 Correct 65 ms 10720 KB Output is correct
9 Correct 70 ms 10796 KB Output is correct
10 Correct 287 ms 10720 KB Output is correct
11 Correct 6 ms 6220 KB Output is correct
12 Correct 70 ms 10748 KB Output is correct
13 Correct 72 ms 10656 KB Output is correct
14 Correct 66 ms 10612 KB Output is correct
15 Correct 84 ms 10616 KB Output is correct
16 Correct 178 ms 10964 KB Output is correct
17 Correct 104 ms 10656 KB Output is correct
18 Correct 74 ms 10764 KB Output is correct
19 Correct 36 ms 7072 KB Output is correct
20 Correct 63 ms 10648 KB Output is correct
21 Correct 83 ms 10820 KB Output is correct
22 Correct 250 ms 10612 KB Output is correct
23 Correct 7 ms 6228 KB Output is correct
24 Correct 70 ms 10696 KB Output is correct
25 Correct 65 ms 10692 KB Output is correct
26 Correct 76 ms 10676 KB Output is correct
27 Correct 64 ms 10600 KB Output is correct
28 Correct 166 ms 10840 KB Output is correct
29 Correct 102 ms 10692 KB Output is correct
30 Correct 67 ms 10792 KB Output is correct
31 Correct 1597 ms 52460 KB Output is correct
32 Correct 1504 ms 59480 KB Output is correct
33 Correct 1456 ms 52432 KB Output is correct
34 Correct 1099 ms 57656 KB Output is correct
35 Correct 5134 ms 49304 KB Output is correct
36 Correct 5532 ms 50324 KB Output is correct
37 Correct 1679 ms 97592 KB Output is correct
38 Correct 35 ms 7716 KB Output is correct
39 Correct 83 ms 11960 KB Output is correct
40 Correct 77 ms 11864 KB Output is correct
41 Correct 245 ms 11872 KB Output is correct
42 Correct 8 ms 6220 KB Output is correct
43 Correct 82 ms 11928 KB Output is correct
44 Correct 69 ms 11896 KB Output is correct
45 Correct 76 ms 11804 KB Output is correct
46 Correct 70 ms 11656 KB Output is correct
47 Correct 164 ms 12008 KB Output is correct
48 Correct 107 ms 11844 KB Output is correct
49 Correct 73 ms 12020 KB Output is correct
50 Correct 1647 ms 90808 KB Output is correct
51 Correct 1524 ms 97876 KB Output is correct
52 Correct 1496 ms 91012 KB Output is correct
53 Correct 1188 ms 96236 KB Output is correct
54 Correct 5250 ms 88044 KB Output is correct
55 Correct 5993 ms 88584 KB Output is correct
56 Correct 1737 ms 97644 KB Output is correct
57 Incorrect 1786 ms 91708 KB Output isn't correct
58 Halted 0 ms 0 KB -