結果
| 問題 |
No.3326 岩井星人の帰星
|
| コンテスト | |
| ユーザー |
のらら
|
| 提出日時 | 2025-10-26 21:24:31 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,274 bytes |
| コンパイル時間 | 3,627 ms |
| コンパイル使用メモリ | 183,424 KB |
| 実行使用メモリ | 23,088 KB |
| 最終ジャッジ日時 | 2025-11-01 12:39:44 |
| 合計ジャッジ時間 | 17,236 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 58 TLE * 1 |
ソースコード
//多始点BFS(嘘解法)
#include <iostream>
#include <algorithm>
#include <atcoder/all>
#include <queue>
using namespace std;
using namespace atcoder;
using ll = long long;
//#define endl "\n";
ll N, M, L;
vector<vector<int>> G;
int main(){
cin >> N >> M;
G.resize(N + 1);
for(int i = 0; i < M; i++){
ll a, b;
cin >> a >> b;
G[a].push_back(b);
G[b].push_back(a);
}
cin >> L;
queue<pair<ll, ll>> quep;
vector<ll> chk(N + 1, -1);
for(int i = 0; i < L; i++){
ll j, k;
cin >> j >> k;
chk[j] = k;
quep.push({j, chk[j]});
}
while(!quep.empty()){
auto [pos, d] = quep.front(); quep.pop();
for(auto to: G[pos]){
if(chk[to] < d - 1){
chk[to] = d - 1;
quep.push({to, chk[to]});
}
}
}
queue<ll> que;
vector<ll> dist(N + 1, -1);
if(chk[1] != -1){
cout << "No" << endl;
}else{
dist[1] = 0;
que.push(1);
while(!que.empty()){
int pos = que.front(); que.pop();
for(auto to: G[pos]){
if(dist[to] == -1 && chk[to] == -1){
dist[to] = dist[pos] + 1;
que.push(to);
}
}
}
if(dist[N] == -1){
cout << "No" << endl;
}else{
cout << "Yes" << endl;
cout << dist[N] << endl;
}
}
return 0;
}
のらら