結果

問題 No.3263 違法な散歩道
ユーザー kotatsugame
提出日時 2025-09-06 13:34:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 837 bytes
コンパイル時間 666 ms
コンパイル使用メモリ 77,656 KB
実行使用メモリ 12,872 KB
最終ジャッジ日時 2025-09-06 13:34:21
合計ジャッジ時間 3,122 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:21: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   34 |                 auto[u,t]=Q.front();Q.pop();
      |                     ^

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
#include<cassert>
using namespace std;
int N,M;
vector<int>G[1<<17];
bool ex[1<<17];
int dist[1<<17][5];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>M;
	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 K;cin>>K;
	for(;K--;)
	{
		int a;cin>>a;
		ex[a-1]=true;
	}
	queue<pair<int,int> >Q;
	Q.push(make_pair(0,0));
	for(int i=0;i<N;i++)for(int j=0;j<5;j++)dist[i][j]=1e9;
	dist[0][0]=0;
	while(!Q.empty())
	{
		auto[u,t]=Q.front();Q.pop();
		if(u==N-1)
		{
			cout<<dist[u][t]<<endl;
			return 0;
		}
		int nd=dist[u][t]+1;
		for(int v:G[u])
		{
			int nt=t;
			if(ex[v])nt++;
			else nt=0;
			if(nt<5&&dist[v][nt]>nd)
			{
				dist[v][nt]=nd;
				Q.push(make_pair(v,nt));
			}
		}
	}
	cout<<-1<<endl;
}
0