結果
| 問題 | No.3263 違法な散歩道 |
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2026-10-05 23:50:45 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 40 ms / 2,000 ms |
| + 829µs | |
| コード長 | 1,033 bytes |
| 記録 | |
| コンパイル時間 | 2,404 ms |
| コンパイル使用メモリ | 349,608 KB |
| 実行使用メモリ | 17,080 KB |
| 最終ジャッジ日時 | 2026-10-05 23:50:54 |
| 合計ジャッジ時間 | 6,531 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
cin.tie(0)->sync_with_stdio(0);
ll n,m;cin>>n>>m;
vector<vector<ll>>g(n);
for(int i=0;i<m;i++)
{
ll u,v;cin>>u>>v;
u--;v--;
g[u].push_back(v);
g[v].push_back(u);
}
ll k;cin>>k;
vector<bool>isa(n);
for(int i=0;i<k;i++)
{
ll a;cin>>a;
a--;
isa[a]=true;
}
queue<pair<ll,ll>>que;
vector dist(n,vector<ll>(5,-1));
que.push({0,0});
dist[0][0]=0;
while(!que.empty())
{
auto[now,cnt]=que.front();
que.pop();
for(ll nex:g[now])
{
ll cntnex=0;
if(isa[nex])cntnex=cnt+1;
if(cntnex==5)continue;
if(dist[nex][cntnex]!=-1)continue;
dist[nex][cntnex]=dist[now][cnt]+1;
que.push({nex,cntnex});
}
}
ll ans=1LL<<60;
for(auto o:dist[n-1])if(o!=-1)ans=min(ans,o);
if(ans==1LL<<60)cout<<-1<<endl;
else cout<<ans<<endl;
}