結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー 👑 kmjpkmjp
提出日時 2016-12-18 00:10:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 1,501 bytes
コンパイル時間 3,044 ms
コンパイル使用メモリ 152,124 KB
実行使用メモリ 43,704 KB
最終ジャッジ日時 2023-08-20 22:04:45
合計ジャッジ時間 7,965 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
36,288 KB
testcase_01 AC 18 ms
36,036 KB
testcase_02 AC 16 ms
36,160 KB
testcase_03 AC 15 ms
36,384 KB
testcase_04 AC 14 ms
36,188 KB
testcase_05 AC 18 ms
36,196 KB
testcase_06 AC 16 ms
36,300 KB
testcase_07 AC 18 ms
36,380 KB
testcase_08 AC 18 ms
36,092 KB
testcase_09 AC 15 ms
36,104 KB
testcase_10 AC 18 ms
36,160 KB
testcase_11 AC 15 ms
36,180 KB
testcase_12 AC 17 ms
36,208 KB
testcase_13 AC 15 ms
36,188 KB
testcase_14 AC 19 ms
36,164 KB
testcase_15 AC 19 ms
36,120 KB
testcase_16 AC 17 ms
36,272 KB
testcase_17 AC 17 ms
36,176 KB
testcase_18 AC 17 ms
36,248 KB
testcase_19 AC 17 ms
36,120 KB
testcase_20 AC 17 ms
36,176 KB
testcase_21 AC 17 ms
36,140 KB
testcase_22 AC 17 ms
36,172 KB
testcase_23 AC 19 ms
36,284 KB
testcase_24 AC 209 ms
43,456 KB
testcase_25 AC 187 ms
43,496 KB
testcase_26 AC 190 ms
43,492 KB
testcase_27 AC 187 ms
43,660 KB
testcase_28 AC 187 ms
43,368 KB
testcase_29 AC 190 ms
43,400 KB
testcase_30 AC 188 ms
43,356 KB
testcase_31 AC 196 ms
43,480 KB
testcase_32 AC 187 ms
43,704 KB
testcase_33 AC 189 ms
43,368 KB
testcase_34 AC 54 ms
42,784 KB
testcase_35 AC 14 ms
36,140 KB
testcase_36 AC 13 ms
36,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int A[505050],B[505050],C[505050],W[505050];
vector<int> E[505050];
vector<int> F[505050];

int st[505050],ed[505050];

void solve() {
	int i,j,k,l,r,x,y; string s;
	cin>>N>>M;
	FOR(i,M) {
		cin>>A[i]>>B[i]>>C[i];
		E[A[i]].push_back(i);
		F[B[i]].push_back(i);
		W[B[i]]++;
	}
	queue<int> Q;
	FOR(i,N) if(W[i]==0) Q.push(i);
	while(Q.size()) {
		int k=Q.front();
		Q.pop();
		FORR(r,E[k]) {
			st[B[r]] = max(st[B[r]],st[k]+C[r]);
			W[B[r]]--;
			if(W[B[r]]==0) Q.push(B[r]);
		}
	}
	FOR(i,M) W[A[i]]++;
	FOR(i,N) {
		ed[i]=1<<30;
		if(W[i]==0) Q.push(i);
	}
	ed[N-1]=st[N-1];
	while(Q.size()) {
		int k=Q.front();
		Q.pop();
		FORR(r,F[k]) {
			ed[A[r]] = min(ed[A[r]],ed[k]-C[r]);
			W[A[r]]--;
			if(W[A[r]]==0) Q.push(A[r]);
		}
	}
	int ret=0;
	FOR(i,N) if(st[i]!=ed[i]) ret++;
	
	cout<<st[N-1]<<" "<<ret<<"/"<<N<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0