結果
問題 |
No.3263 違法な散歩道
|
ユーザー |
|
提出日時 | 2025-09-06 13:47:49 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 184 ms / 2,000 ms |
コード長 | 2,906 bytes |
コンパイル時間 | 6,295 ms |
コンパイル使用メモリ | 334,360 KB |
実行使用メモリ | 18,908 KB |
最終ジャッジ日時 | 2025-09-06 13:48:29 |
合計ジャッジ時間 | 10,453 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; // #include <boost/multiprecision/cpp_int.hpp> // using namespace boost::multiprecision; // # pragma GCC target("avx2") // # pragma GCC optimize("O3") // # pragma GCC optimize("unroll-loops") #define ll long long #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define vi vector<int> #define vl vector<ll> #define vd vector<double> #define vb vector<bool> #define vs vector<string> #define vc vector<char> #define ull unsigned long long #define chmax(a,b) a=max(a,b) #define chmin(a,b) a=min(a,b) ll inf=(1ll<<60); // const double PI=3.1415926535897932384626433832795028841971; // ll rui(ll a,ll b){ // if(b==0)return 1; // if(b%2==1) return a*rui(a*a,b/2); // return rui(a*a,b/2); // } // ll kai(ll n){ // if(n==0)return 1; // return n*kai(n-1); // } // using mint = modint998244353;//static_modint<998244353> // using mint = modint1000000007;//static_modint<1000000007> // using mint = modint;//mint::set_mod(mod); // ll const mod=1000000007ll; // ll const mod=998244353ll; // ll modrui(ll a,ll b,ll mod){ // a%=mod; // if(b==0)return 1; // if(b%2==1) return a*modrui(a*a%mod,b/2,mod)%mod; // return modrui(a*a%mod,b/2,mod)%mod; // } // ll inv(ll x){ // x%=mod; // return modrui(x,mod-2); // } // ll modkai(ll n){ // ll ret=1; // rep(i,n){ // ret*=(i+1)%mod; // ret%=mod; // } // return ret; // } // void incr(vl &v,ll n){ // ll k=v.size(); // v[k-1]++; // ll now=k-1; // while (v[now]>=n) // { // v[now]=0; // if(now==0)break; // v[now-1]++; // now--; // } // return; // } void solve(){ ll n,m; cin >> n >> m; vector<vl> g(n); rep(i,m){ ll u,v; cin >> u >> v; u--; v--; g[u].push_back(v); g[v].push_back(u); } ll c; cin >> c; vb a(n,0); rep(i,c){ ll x; cin >> x; x--; a[x]=1; } vector<vl> dist(n,vl(5,inf)); deque<vl> dq(0); dist[0][0]=0; dq={{0,0,0}}; while(!dq.empty()){ ll nowdist=dq[0][0],nowx=dq[0][1],nowcnt=dq[0][2]; dq.pop_front(); for(auto &to:g[nowx]){ if(a[to]){ if(nowcnt+1<5 && dist[to][nowcnt+1]>nowdist+1){ dist[to][nowcnt+1]=nowdist+1; dq.push_back({nowdist+1,to,nowcnt+1}); } } else{ if(dist[to][0]>nowdist+1){ dist[to][0]=nowdist+1; dq.push_back({nowdist+1,to,0}); } } } } cout << (dist[n-1][0]==inf? -1:dist[n-1][0]) <<"\n"; } int main(){ // ios::sync_with_stdio(false); // std::cin.tie(nullptr); ll t=1; // cin >> t; while(t--)solve(); }