結果
問題 | No.468 役に立つ競技プログラミング実践編 |
ユーザー | tubo28 |
提出日時 | 2016-12-13 20:21:17 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 446 ms / 2,000 ms |
コード長 | 3,681 bytes |
コンパイル時間 | 1,902 ms |
コンパイル使用メモリ | 183,496 KB |
実行使用メモリ | 33,668 KB |
最終ジャッジ日時 | 2024-05-07 09:58:04 |
合計ジャッジ時間 | 7,799 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 3 ms
5,376 KB |
testcase_09 | AC | 3 ms
5,376 KB |
testcase_10 | AC | 3 ms
5,376 KB |
testcase_11 | AC | 3 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 5 ms
5,376 KB |
testcase_15 | AC | 5 ms
5,376 KB |
testcase_16 | AC | 6 ms
5,376 KB |
testcase_17 | AC | 6 ms
5,376 KB |
testcase_18 | AC | 5 ms
5,376 KB |
testcase_19 | AC | 6 ms
5,376 KB |
testcase_20 | AC | 5 ms
5,376 KB |
testcase_21 | AC | 5 ms
5,376 KB |
testcase_22 | AC | 6 ms
5,376 KB |
testcase_23 | AC | 5 ms
5,376 KB |
testcase_24 | AC | 446 ms
33,612 KB |
testcase_25 | AC | 437 ms
33,576 KB |
testcase_26 | AC | 425 ms
33,668 KB |
testcase_27 | AC | 423 ms
33,532 KB |
testcase_28 | AC | 435 ms
33,480 KB |
testcase_29 | AC | 435 ms
33,544 KB |
testcase_30 | AC | 428 ms
33,508 KB |
testcase_31 | AC | 441 ms
33,500 KB |
testcase_32 | AC | 428 ms
33,484 KB |
testcase_33 | AC | 421 ms
33,476 KB |
testcase_34 | AC | 116 ms
23,100 KB |
testcase_35 | AC | 3 ms
5,376 KB |
testcase_36 | AC | 2 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(dst, N) for (int dst = 0; dst < (int)(N); ++dst) #define all(C) begin(C), end(C) #define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl using Weight = int; using Capacity = int; struct Edge { int src, dst; Weight weight; Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {} }; using Edges = vector<Edge>; using Graph = vector<Edges>; using Array = vector<Weight>; using Matrix = vector<Array>; vector<int> tarjan_scc(const Graph &g) { int n = g.size(), sz = 0; Graph rg(n); vector<int> stk, cmp(n, -1), added(n), visited(n), ord(n); for (auto &es : g) { for (auto &e : es) rg[e.dst].emplace_back(e.dst, e.src, e.weight); sz += es.size(); } stk.resize(n + sz); sz = 0; for (int i = 0; i < n; i++) { if (visited[i]) continue; int s = 0; stk[s++] = i; while (s != 0) { int v = stk[s - 1]; visited[v] = true; bool pushed = false; for (auto &e : g[v]) { int dst = e.dst; if (!visited[dst]) { stk[s++] = dst; pushed = true; } } if (pushed) continue; int t = stk[s - 1]; if (!added[t]) { added[t] = true; ord[n - ++sz] = t; } --s; } } int k = 0; for (int &u : ord) { if (cmp[u] != -1) continue; int s = 0; stk[s++] = u; while (s != 0) { int v = stk[--s]; cmp[v] = k; for (auto &e : rg[v]) { int d = e.dst; if (cmp[d] == -1) stk[s++] = d; } } ++k; } return cmp; } bool in_range(int x, int l, int r) { return l <= x && x <= r; } bool acyclic(const Graph &g) { vector<int> a = tarjan_scc(g); sort(all(a)); a.erase(unique(all(a)), a.end()); return a.size() == g.size(); } void visit(const Graph &g, int u, int *vis) { if (vis[u]) return; vis[u] = true; for (auto &e : g[u]) visit(g, e.dst, vis); } bool all_reachable(const Graph &g, int u) { static int vis[100010]; memset(vis, 0, sizeof vis); visit(g, u, vis); int cnt = count(vis, vis + g.size(), true); return cnt == g.size(); } int N, M; Graph g, rg; int dpb[100010], dpr[100010]; int blue(int u) { int &res = dpb[u]; if (res != -1) return res; res = 0; for (auto &e : rg[u]) res = max(res, blue(e.dst) + e.weight); return res; } int red(int u) { int &res = dpr[u]; if (res != -1) return res; res = 1e9; for (auto &e : g[u]) res = min(res, red(e.dst) - e.weight); return res; } int main() { cin >> N >> M; assert(in_range(N, 3, 100000)); assert(in_range(M, 2, 500000)); g.assign(N, {}); rg.assign(N, {}); memset(dpb, -1, sizeof dpb); memset(dpr, -1, sizeof dpr); for (int i = 0; i < M; i++) { int A, B, C; cin >> A >> B >> C; assert(in_range(A, 0, N - 1)); assert(in_range(B, 0, N - 1)); assert(in_range(C, 0, 160 - 1)); g[A].emplace_back(A, B, C); rg[B].emplace_back(B, A, C); } assert(g[N - 1].size() == 0); assert(rg[0].size() == 0); assert(acyclic(g)); assert(acyclic(rg)); assert(all_reachable(g, 0)); assert(all_reachable(rg, N - 1)); blue(N - 1); dpr[N - 1] = dpb[N - 1]; red(0); int p = 0; for (int i = 0; i < N; i++) { if (dpb[i] != dpr[i]) ++p; } printf("%d %d/%d\n", blue(N - 1), p, N); }