結果
| 問題 |
No.3326 岩井星人の帰星
|
| コンテスト | |
| ユーザー |
mtmr_s1
|
| 提出日時 | 2025-11-01 16:32:41 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,923 bytes |
| コンパイル時間 | 4,636 ms |
| コンパイル使用メモリ | 255,632 KB |
| 実行使用メモリ | 30,832 KB |
| 最終ジャッジ日時 | 2025-11-01 16:32:57 |
| 合計ジャッジ時間 | 12,551 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 56 WA * 3 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef modint998244353 mint;
//typedef modint1000000007 mint;
void chmin(ll& a, ll b) { a = min(a, b); }
void chmax(ll& a, ll b) { a = max(a, b); }
int N, M;
bool IsSeen[200200];
int dfs(vector<vector<int>>& G, vector<int>& State, int now){
IsSeen[now] = true;
if(now == N - 1){
return 0;
}
int ans = INT_MAX / 2;
for(int i = 0; i < G[now].size(); i++){
int neighbor = G[now][i];
if(State[neighbor] == -1 && !IsSeen[neighbor]){
ans = min(ans, dfs(G, State, neighbor) + 1);
}
}
return ans;
}
int main() {
cin >> N >> M;
vector<vector<int>> G(N);
for(int i = 0; i < M; i++){
int u, v;
cin >> u >> v;
u--; v--;
G[u].push_back(v);
G[v].push_back(u);
}
int L;
cin >> L;
priority_queue<pair<int, int>> Q;
vector<int> State(N, -1);
for(int i = 0; i < L; i++){
int J, K;
cin >> J >> K;
J--;
if(State[J] < K){
State[J] = K;
Q.push({K, J});
}
}
// マルチソースBFS
int count = 0;
while(!Q.empty()){
pair<int, int> now = Q.top();
Q.pop();
if(State[now.second] > 0 && State[now.second] == now.first){
for(int i = 0; i < G[now.second].size(); i++){
int neighbor = G[now.second][i];
if(State[neighbor] < State[now.second] - 1){
State[neighbor] = State[now.second] - 1;
Q.push({State[neighbor], neighbor});
}
}
}
}
fill(IsSeen, IsSeen + N, false);
int result = dfs(G, State, 0);
if(result > INT_MAX / 3){
cout << "No" << endl;
}else{
cout << "Yes" << endl;
cout << result << endl;
}
}
mtmr_s1