結果

問題 No.1393 Median of Walk
ユーザー kotatsugamekotatsugame
提出日時 2021-02-13 04:16:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,317 bytes
コンパイル時間 1,033 ms
コンパイル使用メモリ 89,908 KB
実行使用メモリ 5,464 KB
最終ジャッジ日時 2023-09-27 11:24:18
合計ジャッジ時間 3,995 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 28 ms
4,380 KB
testcase_09 AC 30 ms
4,380 KB
testcase_10 AC 27 ms
4,380 KB
testcase_11 AC 36 ms
4,380 KB
testcase_12 AC 105 ms
4,380 KB
testcase_13 AC 15 ms
4,376 KB
testcase_14 AC 124 ms
4,376 KB
testcase_15 AC 35 ms
4,376 KB
testcase_16 AC 10 ms
4,376 KB
testcase_17 AC 9 ms
4,380 KB
testcase_18 AC 9 ms
4,380 KB
testcase_19 AC 9 ms
4,380 KB
testcase_20 AC 64 ms
5,464 KB
testcase_21 AC 56 ms
4,380 KB
testcase_22 AC 83 ms
4,376 KB
testcase_23 AC 20 ms
4,380 KB
testcase_24 AC 39 ms
4,380 KB
testcase_25 AC 25 ms
4,376 KB
testcase_26 AC 25 ms
4,380 KB
testcase_27 AC 25 ms
4,380 KB
testcase_28 AC 6 ms
4,376 KB
testcase_29 AC 7 ms
4,380 KB
testcase_30 AC 20 ms
4,380 KB
testcase_31 AC 20 ms
4,380 KB
testcase_32 AC 86 ms
4,380 KB
testcase_33 AC 9 ms
4,376 KB
testcase_34 AC 85 ms
4,380 KB
testcase_35 AC 8 ms
4,380 KB
testcase_36 AC 22 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 24 ms
4,376 KB
testcase_39 AC 9 ms
4,376 KB
testcase_40 AC 10 ms
4,376 KB
testcase_41 AC 12 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:10:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   10 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
int N,M;
int dist[1010];
int ans[1010];
vector<pair<int,int> >G[1010];
main()
{
	cin>>N>>M;
	vector<pair<int,pair<int,int> > >E(M);
	for(int i=0;i<M;i++)
	{
		int u,v,w;cin>>u>>v>>w;
		u--,v--;
		E[i]=make_pair(w,make_pair(u,v));
		G[u].push_back(make_pair(v,1));
	}
	sort(E.begin(),E.end());
	for(int i=0;i<N;i++)ans[i]=dist[i]=2e9;
	dist[0]=0;
	{
		queue<int>P;
		P.push(0);
		while(!P.empty())
		{
			int u=P.front();P.pop();
			for(pair<int,int>e:G[u])
			{
				int v=e.first;
				if(dist[v]>dist[u]+e.second)
				{
					dist[v]=dist[u]+e.second;
					P.push(v);
				}
			}
		}
	}
	for(pair<int,pair<int,int> >e:E)
	{
		G[e.second.first].push_back(make_pair(e.second.second,-1));
		priority_queue<pair<int,int> >P;
		P.push(make_pair(-dist[e.second.first],e.second.first));
		while(!P.empty())
		{
			int u=P.top().second,cost=-P.top().first;
			P.pop();
			if(dist[u]<cost)continue;
			for(pair<int,int>e:G[u])
			{
				int v=e.first;
				int nxt=dist[u]+e.second;
				if(dist[v]>-N&&dist[v]>nxt)
				{
					dist[v]=nxt;
					P.push(make_pair(-nxt,v));
				}
			}
		}
		for(int i=0;i<N;i++)if(dist[i]<=0)
		{
			if(ans[i]==(int)2e9)ans[i]=e.first;
		}
	}
	for(int i=1;i<N;i++)cout<<(ans[i]<(int)2e9?ans[i]:-1)<<endl;
}
0