結果
| 問題 |
No.3326 岩井星人の帰星
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-01 16:21:21 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 206 ms / 2,000 ms |
| コード長 | 2,617 bytes |
| コンパイル時間 | 7,996 ms |
| コンパイル使用メモリ | 357,092 KB |
| 実行使用メモリ | 22,512 KB |
| 最終ジャッジ日時 | 2025-11-01 16:21:38 |
| 合計ジャッジ時間 | 13,995 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 59 |
ソースコード
#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#endif
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
#endif
constexpr int inf = (1 << 30) - 1;
constexpr long long linf = (1LL << 60) - 1;
using ll = long long;
using ld = long double;
#define len(x) int((x).size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define LB(c, x) distance(begin(c), lower_bound(all(c), x))
#define UB(c, x) distance(begin(c), upper_bound(all(c), x))
template <typename F> ll binary_search(F check, ll ok, ll ng, bool CHECK = true) { if(CHECK) assert(check(ok)); while(abs(ok - ng) > 1) { ll mi = (ok + ng) / 2; (check(mi) ? ok : ng) = mi; } return ok; }
template <typename T, typename S> auto min(const T& a, const S& b) { return(a < b ? a : b); }
template <typename T, typename S> auto max(const T& a, const S& b) { return(a > b ? a : b); }
template <typename T, typename S> inline bool chmin(T& a, const S& b) { return(a > b ? a = b, 1 : 0); }
template <typename T, typename S> inline bool chmax(T& a, const S& b) { return(a < b ? a = b, 1 : 0); }
#include <atcoder/dsu>
void solve() {
int n, m; cin >> n >> m;
vector<vector<int>> g(n);
vector<pair<int,int>>E;
for(int i = 0; i < m; i++) {
int a, b; cin >> a >> b;
a--; b--;
g[a].push_back(b);
g[b].push_back(a);
E.push_back({a,b});
}
int L;
cin >> L;
vector<ll> dp(n, -1);
for(int i = 0; i < L; i++) {
int p, h; cin >> p >> h;
dp[--p] = h;
}
priority_queue<pair<ll, ll>> pq;
for(int i = 0; i < n; i++) if(dp[i] > 0) pq.push({dp[i], i});
while(!pq.empty()) {
auto[d, v] = pq.top(); pq.pop();
if(dp[v] != d) continue;
if(dp[v] == 0) continue;
for(auto&&nv: g[v]) {
if(chmax(dp[nv], dp[v] - 1)) {
pq.push({dp[nv], nv});
}
}
}
if(dp[0]>=0) {
cout << "No" << "\n";
} else {
queue<int>Q;
Q.push(0);
vector<int>dist(n,-1);
dist[0]=0;
while(!Q.empty()) {
int v = Q.front();
Q.pop();
for(int u: g[v]) if(dp[u] < 0 && dist[u]<0) {
dist[u] = dist[v]+1;
Q.push(u);
}
}
if(dist.back()<0) cout << "No\n";
else {
cout << "Yes\n";
cout << dist.back() << "\n";
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
while(T--) {
solve();
}
}