답안 #727363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
727363 2023-04-20T13:35:49 Z finn__ From Hacks to Snitches (BOI21_watchmen) C++17
0 / 100
73 ms 11948 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] || (d + 1) % mod[v] == resid_class[v])))
            {
                if (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 16 ms 8660 KB Output is correct
2 Incorrect 48 ms 11888 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 8628 KB Output is correct
2 Incorrect 73 ms 11948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 8628 KB Output is correct
2 Incorrect 73 ms 11948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 8628 KB Output is correct
2 Incorrect 73 ms 11948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 8660 KB Output is correct
2 Incorrect 48 ms 11888 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 8660 KB Output is correct
2 Incorrect 48 ms 11888 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 8660 KB Output is correct
2 Incorrect 48 ms 11888 KB Output isn't correct
3 Halted 0 ms 0 KB -