結果

問題 No.1190 Points
ユーザー kotatsugamekotatsugame
提出日時 2020-08-22 16:40:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 294 ms / 2,000 ms
コード長 1,314 bytes
コンパイル時間 950 ms
コンパイル使用メモリ 79,920 KB
実行使用メモリ 11,784 KB
最終ジャッジ日時 2024-04-23 10:40:22
合計ジャッジ時間 6,665 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,528 KB
testcase_01 AC 4 ms
6,656 KB
testcase_02 AC 3 ms
6,784 KB
testcase_03 AC 138 ms
10,400 KB
testcase_04 AC 94 ms
9,984 KB
testcase_05 AC 149 ms
9,600 KB
testcase_06 AC 108 ms
11,136 KB
testcase_07 AC 222 ms
11,520 KB
testcase_08 AC 274 ms
11,784 KB
testcase_09 AC 260 ms
11,232 KB
testcase_10 AC 273 ms
11,648 KB
testcase_11 AC 185 ms
9,892 KB
testcase_12 AC 264 ms
11,520 KB
testcase_13 AC 162 ms
9,324 KB
testcase_14 AC 26 ms
8,832 KB
testcase_15 AC 277 ms
11,464 KB
testcase_16 AC 20 ms
7,680 KB
testcase_17 AC 249 ms
11,116 KB
testcase_18 AC 102 ms
8,576 KB
testcase_19 AC 19 ms
8,960 KB
testcase_20 AC 139 ms
9,096 KB
testcase_21 AC 43 ms
8,704 KB
testcase_22 AC 52 ms
9,856 KB
testcase_23 AC 294 ms
11,464 KB
testcase_24 AC 277 ms
11,592 KB
testcase_25 AC 135 ms
11,208 KB
testcase_26 AC 96 ms
11,008 KB
testcase_27 AC 140 ms
11,212 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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