結果

問題 No.807 umg tours
ユーザー kotatsugamekotatsugame
提出日時 2019-04-20 02:12:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,576 bytes
コンパイル時間 1,766 ms
コンパイル使用メモリ 90,800 KB
実行使用メモリ 20,760 KB
最終ジャッジ日時 2023-10-24 22:57:59
合計ジャッジ時間 7,106 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,780 KB
testcase_01 WA -
testcase_02 AC 4 ms
6,796 KB
testcase_03 AC 4 ms
6,796 KB
testcase_04 WA -
testcase_05 AC 3 ms
6,784 KB
testcase_06 AC 4 ms
6,796 KB
testcase_07 AC 3 ms
6,792 KB
testcase_08 AC 3 ms
6,764 KB
testcase_09 AC 4 ms
6,768 KB
testcase_10 AC 3 ms
6,772 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 302 ms
12,756 KB
testcase_21 AC 301 ms
12,976 KB
testcase_22 AC 128 ms
9,364 KB
testcase_23 AC 99 ms
8,764 KB
testcase_24 AC 294 ms
17,324 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<pair<long,int> >d1(N,make_pair(-9e18,-2e9));
	vector<long>d2(N,9e18);
	d1[0]=make_pair(0,0);
	priority_queue<pair<pair<long,int>,int> >P;
	P.push(make_pair(make_pair(0,0),0));
	while(!P.empty())
	{
		pair<long,int>p=P.top().first;
		int u=P.top().second;
		P.pop();
		if(d1[u].first>p.first)continue;
		for(int i=0;i<G[u].size();i++)
		{
			pair<long,int>q=p;
			int v=G[u][i].first;
			if(G[u][i].second<-q.second)
			{
				q.first-=G[u][i].second;
				if(d1[G[u][i].first]<q||d1[G[u][i].first].first==q.first&&d1[G[u][i].first].second>q.second)
				{
					d1[G[u][i].first]=q;
					P.push(make_pair(q,v));
				}
			}
			else
			{
				q.first+=q.second;
				q.second=-G[u][i].second;
				if(d1[G[u][i].first]<q||d1[G[u][i].first].first==q.first&&d1[G[u][i].first].second>=q.second)
				{
					d1[G[u][i].first]=q;
					P.push(make_pair(q,v));
				}
			}
		}
	}
	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].first+d2[i]<<endl;
	}
}
0