結果
| 問題 |
No.468 役に立つ競技プログラミング実践編
|
| コンテスト | |
| ユーザー |
cormoran
|
| 提出日時 | 2016-12-20 17:45:05 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 181 ms / 2,000 ms |
| コード長 | 2,810 bytes |
| コンパイル時間 | 1,971 ms |
| コンパイル使用メモリ | 186,776 KB |
| 実行使用メモリ | 23,680 KB |
| 最終ジャッジ日時 | 2024-12-14 11:30:24 |
| 合計ジャッジ時間 | 5,259 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 31 |
| other | AC * 6 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
template<class T> bool set_min(T &a, const T &b) { return a > b ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }
const int INF = 1 << 30;
class Solver {
public:
int N, M;
vector<vector<pii>> E;
vector<vector<pii>> RE;
vector<int> earliest, latest;
int calc_earliest(int now) {
if(earliest[now] >= 0) return earliest[now];
int res = 0;
for(auto e : RE[now]) {
set_max(res, calc_earliest(e.first) + e.second);
}
return earliest[now] = res;
}
int calc_latest(int now) {
if(latest[now] < INF) return latest[now];
int res = earliest[N - 1];
for(auto e: E[now]) {
set_min(res, calc_latest(e.first) - e.second);
}
return latest[now] = res;
}
set<int> calc_critical_path(const vector<int> &earliest, const vector<int> &latest) {
set<int> ret;
queue<int> que;
que.push(N - 1);
while(que.size()) {
int now = que.front(); que.pop();
if(ret.count(now)) continue;
ret.insert(now);
for(auto e : RE[now]) {
if(earliest[e.first] == latest[e.first]) {
if(not ret.count(e.first)) {
que.push(e.first);
}
}
}
}
return ret;
}
bool solve() {
cin >> N >> M;
E.resize(N);
RE.resize(N);
rep(i, M) {
int a, b, c; cin >> a >> b >> c;
E[a].push_back(make_pair(b, c));
RE[b].push_back(make_pair(a, c));
}
earliest.resize(N, -1);
latest.resize(N, INF);
calc_earliest(N - 1);
calc_latest(0);
//cerr << earliest << endl;
//cerr << latest << endl;
//cerr << calc_critical_path(earliest, latest) << endl;
int T = earliest[N - 1];
int P = N - calc_critical_path(earliest, latest).size();
cout << T << " " << P << "/" << N << endl;
return 0;
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
Solver s;
s.solve();
return 0;
}
cormoran