結果

問題 No.1190 Points
ユーザー kotatsugame
提出日時 2020-08-22 16:40:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 248 ms / 2,000 ms
コード長 1,314 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 79,872 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-10-15 10:34:35
合計ジャッジ時間 5,683 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int N,M,P;
int s,t;
vector<int>G[1<<17];
int ds[2][1<<17],dt[2][1<<17];
main()
{
	cin>>N>>M>>P>>s>>t;
	s--,t--;
	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);
	}
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<2;j++)
		{
			ds[j][i]=P+1;
			dt[j][i]=P+1;
		}
	}
	{
		ds[0][s]=0;
		priority_queue<pair<int,int> >P;
		P.push(make_pair(0,s));
		while(!P.empty())
		{
			int c=-P.top().first,u=P.top().second;
			P.pop();
			int f=c%2;
			for(int v:G[u])
			{
				int nc=c+1;
				int nf=nc%2;
				if(ds[nf][v]>nc)
				{
					ds[nf][v]=nc;
					P.push(make_pair(-nc,v));
				}
			}
		}
		dt[0][t]=0;
		P.push(make_pair(0,t));
		while(!P.empty())
		{
			int c=-P.top().first,u=P.top().second;
			P.pop();
			int f=c%2;
			for(int v:G[u])
			{
				int nc=c+1;
				int nf=nc%2;
				if(dt[nf][v]>nc)
				{
					dt[nf][v]=nc;
					P.push(make_pair(-nc,v));
				}
			}
		}
	}
	vector<int>ans;
	for(int i=0;i<N;i++)
	{
		bool ok=false;
		for(int js=0;js<2;js++)for(int jt=0;jt<2;jt++)
		{
			int now=ds[js][i]+dt[jt][i];
			if(now<=P&&(P-now)%2==0)ok=true;
		}
		if(ok)ans.push_back(i+1);
	}
	if(ans.empty())
	{
	    cout<<-1<<endl;
	    return 0;
	}
	cout<<ans.size()<<endl;
	for(int a:ans)cout<<a<<endl;
}
0