結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー kotatsugame
提出日時 2019-11-20 01:53:47
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 258 ms / 2,000 ms
コード長 925 bytes
コンパイル時間 704 ms
コンパイル使用メモリ 81,492 KB
実行使用メモリ 20,836 KB
最終ジャッジ日時 2024-10-04 19:19:05
合計ジャッジ時間 5,956 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 31
other AC * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
int N,M;
vector<pair<int,int> >G[1<<17],rG[1<<17];
int cnt[1<<17],rcnt[1<<17];
int d[1<<17],rd[1<<17];
main()
{
	cin>>N>>M;
	for(int i=0;i<M;i++)
	{
		int a,b,c;cin>>a>>b>>c;
		G[a].push_back(make_pair(b,c));
		rG[b].push_back(make_pair(a,c));
		cnt[b]++;
		rcnt[a]++;
	}
	for(int i=0;i<N;i++)rd[i]=1e9;
	queue<int>P;
	P.push(0);
	while(!P.empty())
	{
		int u=P.front();P.pop();
		for(pair<int,int>p:G[u])
		{
			int v=p.first;
			int c=p.second+d[u];
			if(d[v]<c)d[v]=c;
			cnt[v]--;
			if(cnt[v]==0)P.push(v);
		}
	}
	rd[N-1]=d[N-1];
	P.push(N-1);
	while(!P.empty())
	{
		int u=P.front();P.pop();
		for(pair<int,int>p:rG[u])
		{
			int v=p.first;
			int c=rd[u]-p.second;
			if(rd[v]>c)rd[v]=c;
			rcnt[v]--;
			if(rcnt[v]==0)P.push(v);
		}
	}
	int C=0;
	for(int i=0;i<N;i++)C+=d[i]<rd[i];
	cout<<d[N-1]<<" "<<C<<"/"<<N<<endl;
}
0