Submission #441651

# Submission time Handle Problem Language Result Execution time Memory
441651 2021-07-05T16:55:05 Z Ozy From Hacks to Snitches (BOI21_watchmen) C++17
5 / 100
2443 ms 104788 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define lli long long int

#define MAX 100000
#define pos first
#define tiempo second

lli n,m,a,b,k,x,res;
vector<lli> hijos[MAX+2];
lli visitados[127][MAX+2];
queue< pair<lli,lli> > cola;
pair<lli,lli> act;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;
    rep(i,1,m) {
        cin >> a >> b;
        hijos[a].push_back(b);
        hijos[b].push_back(a);
    }

    cin >> k;
    rep(i,1,k) {
        cin >> a;
        x = a;
        rep(j,0,a-1) {
            cin >> b;
            visitados[j][b] = -1;
        }
    }

    cola.push({1,0});
    res = -1;
    while (!cola.empty()) {
        act = cola.front();
        cola.pop();

        a = act.tiempo % x;
        if (visitados[a][act.pos] != 0) continue;
        if (act.pos == n) {res = act.tiempo; break;}
        visitados[a][act.pos] = 1;

        b = (a+1)%x;
        if(visitados[b][act.pos] == 0) cola.push({act.pos, act.tiempo+1});

        for (auto h : hijos[act.pos]){
            if (visitados[b][h] != 0) continue;
            if (visitados[a][h] == -1 && visitados[b][act.pos] == -1) continue;
            cola.push({h,act.tiempo+1});
        }
    }

    if (res == -1) cout << "impossible";
    else cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 20 ms 6988 KB Output is correct
2 Correct 2303 ms 104788 KB Output is correct
3 Correct 2213 ms 97412 KB Output is correct
4 Correct 2148 ms 98484 KB Output is correct
5 Correct 3 ms 3404 KB Output is correct
6 Correct 2443 ms 97752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 6988 KB Output is correct
2 Correct 2411 ms 104788 KB Output is correct
3 Correct 2428 ms 97488 KB Output is correct
4 Correct 2279 ms 98516 KB Output is correct
5 Correct 3 ms 3404 KB Output is correct
6 Correct 2393 ms 97876 KB Output is correct
7 Incorrect 988 ms 50156 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 6988 KB Output is correct
2 Correct 2411 ms 104788 KB Output is correct
3 Correct 2428 ms 97488 KB Output is correct
4 Correct 2279 ms 98516 KB Output is correct
5 Correct 3 ms 3404 KB Output is correct
6 Correct 2393 ms 97876 KB Output is correct
7 Incorrect 988 ms 50156 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 6988 KB Output is correct
2 Correct 2411 ms 104788 KB Output is correct
3 Correct 2428 ms 97488 KB Output is correct
4 Correct 2279 ms 98516 KB Output is correct
5 Correct 3 ms 3404 KB Output is correct
6 Correct 2393 ms 97876 KB Output is correct
7 Incorrect 988 ms 50156 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 6988 KB Output is correct
2 Correct 2303 ms 104788 KB Output is correct
3 Correct 2213 ms 97412 KB Output is correct
4 Correct 2148 ms 98484 KB Output is correct
5 Correct 3 ms 3404 KB Output is correct
6 Correct 2443 ms 97752 KB Output is correct
7 Correct 19 ms 6988 KB Output is correct
8 Correct 2411 ms 104788 KB Output is correct
9 Correct 2428 ms 97488 KB Output is correct
10 Correct 2279 ms 98516 KB Output is correct
11 Correct 3 ms 3404 KB Output is correct
12 Correct 2393 ms 97876 KB Output is correct
13 Incorrect 988 ms 50156 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 6988 KB Output is correct
2 Correct 2303 ms 104788 KB Output is correct
3 Correct 2213 ms 97412 KB Output is correct
4 Correct 2148 ms 98484 KB Output is correct
5 Correct 3 ms 3404 KB Output is correct
6 Correct 2443 ms 97752 KB Output is correct
7 Correct 19 ms 6988 KB Output is correct
8 Correct 2411 ms 104788 KB Output is correct
9 Correct 2428 ms 97488 KB Output is correct
10 Correct 2279 ms 98516 KB Output is correct
11 Correct 3 ms 3404 KB Output is correct
12 Correct 2393 ms 97876 KB Output is correct
13 Incorrect 988 ms 50156 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 6988 KB Output is correct
2 Correct 2303 ms 104788 KB Output is correct
3 Correct 2213 ms 97412 KB Output is correct
4 Correct 2148 ms 98484 KB Output is correct
5 Correct 3 ms 3404 KB Output is correct
6 Correct 2443 ms 97752 KB Output is correct
7 Correct 19 ms 6988 KB Output is correct
8 Correct 2411 ms 104788 KB Output is correct
9 Correct 2428 ms 97488 KB Output is correct
10 Correct 2279 ms 98516 KB Output is correct
11 Correct 3 ms 3404 KB Output is correct
12 Correct 2393 ms 97876 KB Output is correct
13 Incorrect 988 ms 50156 KB Output isn't correct
14 Halted 0 ms 0 KB -