結果

問題 No.807 umg tours
ユーザー kotatsugame
提出日時 2019-04-20 02:07:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,425 bytes
コンパイル時間 1,099 ms
コンパイル使用メモリ 90,736 KB
実行使用メモリ 20,304 KB
最終ジャッジ日時 2024-09-24 18:00:58
合計ジャッジ時間 7,308 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
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]>p)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]=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]=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