結果
| 問題 | No.3326 岩井星人の帰星 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-06-19 15:02:44 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,382 bytes |
| 記録 | |
| コンパイル時間 | 2,865 ms |
| コンパイル使用メモリ | 340,292 KB |
| 実行使用メモリ | 16,580 KB |
| 最終ジャッジ日時 | 2026-06-19 15:03:48 |
| 合計ジャッジ時間 | 50,435 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 54 WA * 1 TLE * 4 |
ソースコード
#include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using l3 = __int128;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using tint = tuple<int, int, int>;
using tll = tuple<ll, ll, ll>;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (int i = 0; i < (n); ++i)
template <typename T>
bool chmax(T &a, const T &b){if(a<b){a=b;return true;}return false;}
template <typename T>
bool chmin(T &a, const T &b){if(a>b){a=b;return true;}return false;}
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = {0, 1, 0, -1}, dx[] = {1, 0, -1, 0};
int main(){
int n,m;cin>>n>>m;
vector<vector<int>> graph(n);
rep(i,m){
int u,v;cin>>u>>v;
u--,v--;
graph[u].push_back(v);
graph[v].push_back(u);
}
int l;cin>>l;
vector<int> dp(n,-1);
rep(i,l){
int j,k;cin>>j>>k;
j--;
chmax(dp[j],k);
}
rep(i,1000)
rep(v,n)
for(auto& nv:graph[v])chmax(dp[nv],dp[v]-1);
queue<int> q;
vector<int> dist(n,inf);
q.push(0);
dist[0]=0;
while(q.size()){
int v=q.front();q.pop();
for(auto& nv:graph[v]){
if(dp[nv]>=0||dist[nv]<=dist[v]+1)continue;
dist[nv]=dist[v]+1;
q.emplace(nv);
}
}
if(dist[n-1]==inf)cout<<"No\n";
else cout<<"Yes\n"<<dist[n-1]<<endl;
}