結果
| 問題 |
No.468 役に立つ競技プログラミング実践編
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-20 02:16:45 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 346 ms / 2,000 ms |
| コード長 | 1,744 bytes |
| コンパイル時間 | 1,231 ms |
| コンパイル使用メモリ | 86,080 KB |
| 実行使用メモリ | 18,580 KB |
| 最終ジャッジ日時 | 2024-12-14 11:02:47 |
| 合計ジャッジ時間 | 6,272 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 31 |
| other | AC * 6 |
ソースコード
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
using namespace std;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }
template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; }
int main() {
int n, m; cin >> n >> m;
vector<vector<pair<int, int> > > g(n);
vector<vector<pair<int, int> > > h(n);
repeat (i,m) {
int a, b, c; cin >> a >> b >> c;
g[a].emplace_back(b, c);
h[b].emplace_back(a, c);
}
vector<int> fast(n); {
reversed_priority_queue<pair<int, int> > que;
vector<int> done(n);
que.emplace(0, 0);
while (not que.empty()) {
int a = que.top().second; que.pop();
for (auto it : g[a]) {
int b, c; tie(b, c) = it;
setmax(fast[b], fast[a] + c);
done[b] += 1;
if (done[b] == h[b].size()) que.emplace(fast[b], b);
}
}
}
vector<int> slow(n, fast[n-1]); {
priority_queue<pair<int, int> > que;
vector<int> done(n);
que.emplace(fast[n-1], n-1);
while (not que.empty()) {
int b = que.top().second; que.pop();
for (auto it : h[b]) {
int a, c; tie(a, c) = it;
setmin(slow[a], slow[b] - c);
done[a] += 1;
if (done[a] == g[a].size()) que.emplace(slow[a], a);
}
}
}
int t = fast[n-1];
int p = 0; repeat (a,n) p += fast[a] < slow[a];
cout << t << ' ' << p << '/' << n << endl;
return 0;
}