結果

問題 No.807 umg tours
ユーザー kotatsugamekotatsugame
提出日時 2019-04-20 01:53:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,393 bytes
コンパイル時間 934 ms
コンパイル使用メモリ 89,168 KB
実行使用メモリ 19,712 KB
最終ジャッジ日時 2023-10-24 22:54:38
合計ジャッジ時間 7,177 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,808 KB
testcase_01 WA -
testcase_02 AC 4 ms
6,824 KB
testcase_03 AC 4 ms
6,824 KB
testcase_04 WA -
testcase_05 AC 4 ms
6,812 KB
testcase_06 AC 4 ms
6,820 KB
testcase_07 AC 3 ms
6,816 KB
testcase_08 AC 4 ms
6,788 KB
testcase_09 AC 4 ms
6,792 KB
testcase_10 AC 3 ms
6,796 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 289 ms
12,052 KB
testcase_21 AC 305 ms
12,244 KB
testcase_22 AC 125 ms
9,056 KB
testcase_23 AC 95 ms
8,524 KB
testcase_24 AC 300 ms
18,812 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