結果

問題 No.1480 Many Complete Graphs
ユーザー kotatsugamekotatsugame
提出日時 2021-04-24 05:48:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 987 bytes
コンパイル時間 694 ms
コンパイル使用メモリ 80,968 KB
実行使用メモリ 29,572 KB
最終ジャッジ日時 2023-09-17 13:28:39
合計ジャッジ時間 6,194 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
19,728 KB
testcase_01 AC 7 ms
19,736 KB
testcase_02 AC 7 ms
19,792 KB
testcase_03 AC 7 ms
19,768 KB
testcase_04 AC 7 ms
19,724 KB
testcase_05 AC 7 ms
19,772 KB
testcase_06 AC 7 ms
19,768 KB
testcase_07 AC 7 ms
19,720 KB
testcase_08 AC 7 ms
19,948 KB
testcase_09 AC 8 ms
19,860 KB
testcase_10 AC 7 ms
20,096 KB
testcase_11 AC 7 ms
19,744 KB
testcase_12 AC 7 ms
19,924 KB
testcase_13 AC 25 ms
21,856 KB
testcase_14 AC 19 ms
21,180 KB
testcase_15 AC 34 ms
22,184 KB
testcase_16 AC 22 ms
21,472 KB
testcase_17 AC 23 ms
21,496 KB
testcase_18 AC 10 ms
20,596 KB
testcase_19 AC 23 ms
21,388 KB
testcase_20 AC 32 ms
21,756 KB
testcase_21 AC 27 ms
21,784 KB
testcase_22 AC 18 ms
20,920 KB
testcase_23 AC 50 ms
23,840 KB
testcase_24 AC 49 ms
22,652 KB
testcase_25 AC 63 ms
23,632 KB
testcase_26 AC 69 ms
24,128 KB
testcase_27 AC 50 ms
22,724 KB
testcase_28 AC 66 ms
25,512 KB
testcase_29 AC 66 ms
25,596 KB
testcase_30 AC 64 ms
25,256 KB
testcase_31 AC 65 ms
25,476 KB
testcase_32 AC 66 ms
25,472 KB
testcase_33 AC 64 ms
25,120 KB
testcase_34 AC 66 ms
25,460 KB
testcase_35 AC 64 ms
25,284 KB
testcase_36 AC 63 ms
25,284 KB
testcase_37 AC 63 ms
25,540 KB
testcase_38 AC 64 ms
25,304 KB
testcase_39 AC 65 ms
25,628 KB
testcase_40 AC 65 ms
25,280 KB
testcase_41 AC 64 ms
25,092 KB
testcase_42 AC 66 ms
25,656 KB
testcase_43 AC 66 ms
25,520 KB
testcase_44 AC 67 ms
25,464 KB
testcase_45 AC 66 ms
25,524 KB
testcase_46 AC 66 ms
25,472 KB
testcase_47 AC 134 ms
27,848 KB
testcase_48 AC 136 ms
28,084 KB
testcase_49 AC 134 ms
27,904 KB
testcase_50 AC 83 ms
27,660 KB
testcase_51 AC 134 ms
27,904 KB
testcase_52 AC 100 ms
26,556 KB
testcase_53 AC 101 ms
26,504 KB
testcase_54 AC 102 ms
26,628 KB
testcase_55 AC 101 ms
26,680 KB
testcase_56 AC 101 ms
26,560 KB
testcase_57 AC 92 ms
29,572 KB
testcase_58 AC 91 ms
28,448 KB
evil_aftercontest.txt AC 175 ms
41,200 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int N,M;
vector<pair<int,int> >G[5<<17];
long dist[5<<17];
main()
{
	cin>>N>>M;
	for(int i=0;i<M;i++)
	{
		int k,c;cin>>k>>c;
		c++;
		for(int j=0;j<k;j++)
		{
			int s;cin>>s;
			s--;
			G[s].push_back(make_pair(N+i*4+s%2,s/2));
			G[N+i*4+2+s%2].push_back(make_pair(s,s/2));
		}
		G[N+i*4].push_back(make_pair(N+i*4+2,c));
		G[N+i*4].push_back(make_pair(N+i*4+3,c+1));
		G[N+i*4+1].push_back(make_pair(N+i*4+2,c+1));
		G[N+i*4+1].push_back(make_pair(N+i*4+3,c+1));
	}
	for(int i=0;i<N+4*M;i++)dist[i]=9e18;
	priority_queue<pair<long,int> >P;
	dist[0]=0;
	P.push(make_pair(0,0));
	while(!P.empty())
	{
		int u=P.top().second;
		long c=-P.top().first;
		P.pop();
		if(dist[u]<c)continue;
		for(pair<int,int>e:G[u])
		{
			int v=e.first;
			long nxt=c+e.second;
			if(dist[v]>nxt)
			{
				dist[v]=nxt;
				P.push(make_pair(-nxt,v));
			}
		}
	}
	long ans=dist[N-1];
	if(ans==(long)9e18)ans=-1;
	cout<<ans<<endl;
}
0