結果
| 問題 | No.3263 違法な散歩道 |
| コンテスト | |
| ユーザー |
T1610
|
| 提出日時 | 2026-10-05 16:08:08 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 883 bytes |
| 記録 | |
| コンパイル時間 | 2,915 ms |
| コンパイル使用メモリ | 347,600 KB |
| 実行使用メモリ | 14,976 KB |
| 最終ジャッジ日時 | 2026-10-05 16:08:16 |
| 合計ジャッジ時間 | 8,016 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 11 WA * 17 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int main(){
int n,m;
cin>>n>>m;
vector<vector<int>> es(n);
rep(i,m) {
int a,b;
cin>>a>>b;
--a;--b;
es[a].emplace_back(b);
es[b].emplace_back(a);
}
int k;
cin>>k;
vector<int> ng(n);
rep(i,k) {
int a;
cin>>a;--a;
ng[a]=1;
}
const int inf=1e9;
const int p=5;
vector<vector<int>> d(n,vector<int>(p,inf));
using T=tuple<int,int,int>;
priority_queue<T,vector<T>,greater<T>> q;
q.emplace(0,0,0);
d[0][0]=0;
while(q.size()){
auto [x,i,j]=q.top();q.pop();
if(d[i][j]!=x) continue;
for(auto to:es[i]) {
int nj=j;
if(ng[to]) nj++;
else nj=0;
if(nj==p) continue;
if(d[i][j]+1>d[to][nj]){
d[to][nj]=d[i][j]+1;
q.emplace(d[to][nj],to,nj);
}
}
}
int ans =*min_element(d.back().begin(),d.back().end());
if(ans==inf)ans=-1;
cout<<ans<<endl;
}
T1610