結果
| 問題 |
No.468 役に立つ競技プログラミング実践編
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-11-23 18:39:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,827 ms / 2,000 ms |
| コード長 | 1,101 bytes |
| コンパイル時間 | 890 ms |
| コンパイル使用メモリ | 82,704 KB |
| 実行使用メモリ | 18,304 KB |
| 最終ジャッジ日時 | 2024-10-11 07:00:22 |
| 合計ジャッジ時間 | 7,586 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 31 |
| other | AC * 6 |
ソースコード
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int main(){
int n, m;
cin >> n >> m;
vector<int> indeg(n, 0), dp(n, 0);
vector<pair<int,int>> v[n], rev[n];
for(int i = 0; i < m; i++){
int a, b, c;
cin >> a >> b >> c;
v[a].push_back({b, c});
rev[b].push_back({a,c});
indeg[b]++;
}
vector<bool> busy(n, 0);
busy[0] = busy[n-1] = true;
queue<int> q;
q.push(0);
while(!q.empty()){
int x = q.front(); q.pop();
for(auto p : v[x]){
dp[p.first] = max(dp[x]+p.second, dp[p.first]);
indeg[p.first]--;
if(indeg[p.first] == 0) q.push(p.first);
}
}
q.push(n-1);
while(!q.empty()){
int x = q.front(); q.pop();
busy[x] = true;
for(auto p : rev[x]){
if(dp[x]-p.second == dp[p.first] && !busy[p.first]){
q.push(p.first);
}
}
}
int k = n;
for(int i = 0; i < n; i++) k -= busy[i];
cout << dp.back() << " " << k << "/" << n << endl;
return 0;
}