結果

問題 No.3326 岩井星人の帰星
コンテスト
ユーザー Riris
提出日時 2025-11-01 16:16:00
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 3,053 bytes
コンパイル時間 3,342 ms
コンパイル使用メモリ 289,212 KB
実行使用メモリ 9,936 KB
最終ジャッジ日時 2025-11-01 16:16:11
合計ジャッジ時間 9,081 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other TLE * 2 -- * 57
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;

using ll = long long;            // 2^63-1まで 負の値は可
using ull = unsigned long long;  // 0<= ull <=2^64-1の範囲 負の値は不可
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<ll, ll>;
template <typename T>
using MNPQ = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using MXPQ = priority_queue<T, vector<T>, less<T>>;

#define rep(i, n) for (int i = 0; i < n; i++)
#define srep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = s; i > n; i--)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define nall(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define vunique(v) v.erase(unique(nall(v)), v.end())
#define IN(a, x) find(nall(a), x) != a.end()
#define YN(flg) cout << (flg ? "Yes" : "No") << "\n"
#define out_grid(x, y, h, w) !(0 <= x && x < h && 0 <= y && y < w)
#define lmd(...) [&](__VA_ARGS__)
#define debug(x) cerr << #x << " = " << x << endl;
const ll INF = 2e18;

template <typename T>
istream& operator>>(istream& is, vector<T>& a) {
    for (auto& x : a) is >> x;
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& a) {
    for (int i = 0; i < (int)a.size(); i++) os << a[i] << " ";
    return os;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << "{" << p.first << "," << p.second << "}";
    return os;
}

template <typename K, typename V>
ostream& operator<<(ostream& os, map<K, V>& a) {
    for (auto& [k, v] : a) os << "{key:" << k << ", item:" << v << "} ";
    return os;
}

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

    ll n, m;
    cin >> n >> m;
    vvl graph(n + 1);
    rep(i, m) {
        ll u, v;
        cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    vector<bool> ng(n + 1);

    ll l;
    cin >> l;
    rep(_, l) {
        ll j, k;
        cin >> j >> k;

        queue<ll> que;
        vector<ll> dist(n + 1, INF);

        que.emplace(j);
        dist[j] = 0;

        while (!que.empty()) {
            auto v = que.front();
            que.pop();
            ng[v] = 1;
            if (dist[v] == k) continue;

            for (auto i : graph[v]) {
                if (dist[i] != INF) continue;
                dist[i] = dist[v] + 1;
                que.emplace(i);
            }
        }
    }

    vector<ll> dist(n + 1, INF);
    queue<ll> que;

    dist[1] = 0;
    que.emplace(1);

    while (!que.empty()) {
        auto v = que.front();
        que.pop();
        if (ng[v]) continue;

        for (auto i : graph[v]) {
            if (dist[i] != INF) continue;
            dist[i] = dist[v] + 1;
            que.emplace(i);
        }
    }

    if (dist[n] != INF) {
        cout << "Yes" << endl;
        cout << dist[n] << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}
0