답안 #727372

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
727372 2023-04-20T13:42:50 Z finn__ From Hacks to Snitches (BOI21_watchmen) C++17
0 / 100
49 ms 10736 KB
#include <bits/stdc++.h>
using namespace std;

constexpr size_t N = 250000;

vector<unsigned> g[N];
unsigned mod[N], resid_class[N], dis[N];

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

    size_t n, m;
    cin >> n >> m;

    for (size_t i = 0; i < m; ++i)
    {
        unsigned u, v;
        cin >> u >> v;
        g[u - 1].push_back(v - 1);
        g[v - 1].push_back(u - 1);
    }

    size_t k;
    cin >> k;

    for (size_t i = 0; i < k; ++i)
    {
        size_t l;
        cin >> l;
        for (size_t j = 0; j < l; ++j)
        {
            unsigned u;
            cin >> u;
            mod[u - 1] = l;
            resid_class[u - 1] = j;
        }
    }

    priority_queue<pair<unsigned, unsigned>, vector<pair<unsigned, unsigned>>, greater<pair<unsigned, unsigned>>> q;
    memset(dis, 255, sizeof dis);
    q.emplace(0, 0);
    dis[0] = 0;

    while (!q.empty())
    {
        auto const [d, u] = q.top();
        q.pop();
        if (d != dis[u])
            continue;

        for (unsigned const &v : g[u])
            if (!(mod[v] && resid_class[v] + 1 == resid_class[u] &&
                  d % mod[v] == resid_class[v]))
            {
                if (!mod[u] && mod[v] && (d + 1) % mod[v] == resid_class[v])
                {
                    if (d + 2 < dis[v])
                    {
                        dis[v] = d + 2;
                        q.emplace(dis[v], v);
                    }
                }
                else if (d + 1 < dis[v])
                {
                    dis[v] = d + 1;
                    q.emplace(dis[v], v);
                }
            }
    }

    cout << dis[n - 1] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8084 KB Output is correct
2 Incorrect 48 ms 10708 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 8000 KB Output is correct
2 Incorrect 49 ms 10736 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 8000 KB Output is correct
2 Incorrect 49 ms 10736 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 8000 KB Output is correct
2 Incorrect 49 ms 10736 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8084 KB Output is correct
2 Incorrect 48 ms 10708 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8084 KB Output is correct
2 Incorrect 48 ms 10708 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8084 KB Output is correct
2 Incorrect 48 ms 10708 KB Output isn't correct
3 Halted 0 ms 0 KB -