結果

問題 No.807 umg tours
ユーザー kotatsugamekotatsugame
提出日時 2019-04-20 01:54:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,395 bytes
コンパイル時間 980 ms
コンパイル使用メモリ 89,608 KB
実行使用メモリ 19,696 KB
最終ジャッジ日時 2023-10-24 22:54:47
合計ジャッジ時間 6,768 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,720 KB
testcase_01 WA -
testcase_02 AC 4 ms
6,740 KB
testcase_03 AC 4 ms
6,736 KB
testcase_04 WA -
testcase_05 AC 4 ms
6,724 KB
testcase_06 AC 4 ms
6,736 KB
testcase_07 AC 4 ms
6,732 KB
testcase_08 AC 3 ms
6,704 KB
testcase_09 AC 3 ms
6,708 KB
testcase_10 AC 3 ms
6,712 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 293 ms
12,036 KB
testcase_21 AC 303 ms
12,228 KB
testcase_22 AC 126 ms
8,984 KB
testcase_23 AC 97 ms
8,512 KB
testcase_24 AC 294 ms
16,552 KB
testcase_25 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
int N,M;
vector<pair<int,int> >G[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));
	}
	vector<long>d1(N,9e18),d2(N,9e18);
	d1[0]=0;
	priority_queue<pair<pair<long,int>,int> >P;
	P.push(make_pair(make_pair(0,0),0));
	while(!P.empty())
	{
		long c=-P.top().first.first;
		int u=P.top().second;
		int m=-P.top().first.second;
		P.pop();
		if(d1[u]<c)continue;
		for(int i=0;i<G[u].size();i++)
		{
			long next=c;
			if(G[u][i].second<m)
			{
				next+=G[u][i].second;
				if(d1[G[u][i].first]>next)
				{
					d1[G[u][i].first]=next;
					P.push(make_pair(make_pair(-next,-m),G[u][i].first));
				}
			}
			else
			{
				next+=m;
				if(d1[G[u][i].first]>next)
				{
					d1[G[u][i].first]=next;
					P.push(make_pair(make_pair(-next,-G[u][i].second),G[u][i].first));
				}
			}
		}
	}
	d2[0]=0;
	priority_queue<pair<long,int> >P2;
	P2.push(make_pair(0,0));
	while(!P2.empty())
	{
		long c=-P2.top().first;
		int u=P2.top().second;
		P2.pop();
		if(d2[u]<c)continue;
		for(int i=0;i<G[u].size();i++)
		{
			int v=G[u][i].first;
			long next=G[u][i].second+c;
			if(d2[v]>next)
			{
				d2[v]=next;
				P2.push(make_pair(-next,v));
			}
		}
	}
	for(int i=0;i<N;i++)
	{
		cout<<d1[i]+d2[i]<<endl;
	}
}
0