結果

問題 No.807 umg tours
ユーザー kotatsugamekotatsugame
提出日時 2019-04-20 02:18:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 501 ms / 4,000 ms
コード長 934 bytes
コンパイル時間 847 ms
コンパイル使用メモリ 83,176 KB
実行使用メモリ 18,608 KB
最終ジャッジ日時 2023-08-15 12:21:01
合計ジャッジ時間 7,465 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,628 KB
testcase_01 AC 4 ms
6,480 KB
testcase_02 AC 4 ms
6,520 KB
testcase_03 AC 3 ms
6,572 KB
testcase_04 AC 3 ms
6,504 KB
testcase_05 AC 4 ms
6,512 KB
testcase_06 AC 3 ms
6,488 KB
testcase_07 AC 3 ms
6,444 KB
testcase_08 AC 3 ms
6,512 KB
testcase_09 AC 3 ms
6,420 KB
testcase_10 AC 3 ms
6,448 KB
testcase_11 AC 262 ms
13,396 KB
testcase_12 AC 282 ms
12,928 KB
testcase_13 AC 368 ms
14,296 KB
testcase_14 AC 160 ms
9,888 KB
testcase_15 AC 125 ms
9,120 KB
testcase_16 AC 387 ms
14,720 KB
testcase_17 AC 490 ms
18,396 KB
testcase_18 AC 501 ms
18,608 KB
testcase_19 AC 476 ms
15,920 KB
testcase_20 AC 296 ms
11,792 KB
testcase_21 AC 302 ms
11,988 KB
testcase_22 AC 124 ms
8,764 KB
testcase_23 AC 96 ms
8,312 KB
testcase_24 AC 292 ms
14,000 KB
testcase_25 AC 477 ms
18,456 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
int N,M;
vector<pair<int,int> >G[1<<17];
long d[2][1<<17];
main()
{
	cin>>N>>M;
	for(int i=0;i<M;i++)
	{
		int a,b,c;cin>>a>>b>>c;
		G[a-1].push_back(make_pair(b-1,c));
		G[b-1].push_back(make_pair(a-1,c));
	}
	for(int i=1;i<N;i++)d[0][i]=d[1][i]=9e18;
	priority_queue<pair<long,pair<int,int> > >P;
	P.push(make_pair(0,make_pair(0,0)));
	while(!P.empty())
	{
		long c=-P.top().first;
		int u=P.top().second.first;
		int f=P.top().second.second;
		P.pop();
		if(d[f][u]<c)continue;
		for(int i=0;i<G[u].size();i++)
		{
			int v=G[u][i].first;
			if(d[f][v]>c+G[u][i].second)
			{
				d[f][v]=c+G[u][i].second;
				P.push(make_pair(-d[f][v],make_pair(v,f)));
			}
			if(f==0)
			{
				if(d[1][v]>c)
				{
					d[1][v]=c;
					P.push(make_pair(-c,make_pair(v,1)));
				}
			}
		}
	}
	for(int i=0;i<N;i++)
	{
		cout<<d[0][i]+d[1][i]<<endl;
	}
}
0