結果
問題 |
No.19 ステージの選択
|
ユーザー |
|
提出日時 | 2024-07-03 22:45:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 20 ms / 5,000 ms |
コード長 | 681 bytes |
コンパイル時間 | 4,364 ms |
コンパイル使用メモリ | 255,588 KB |
最終ジャッジ日時 | 2025-02-22 01:56:04 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; int main(){ int n, p; cin >> n; vector<int> L(n), P(n); vector<bool> used(n); atcoder::scc_graph g(n); for(int i = 0; i < n; i++){ cin >> L[i] >> P[i]; g.add_edge(--P[i], i); } int ans = 0; auto G = g.scc(); for(auto &&a : G){ bool vis = false; for(auto &&v : a){ if(used[P[v]])vis = true; } int minv = 400; for(auto &&v : a){ minv = min(minv, L[v]); ans += L[v]; used[v] = true; } if(!vis)ans += minv; } printf("%d.%d\n",ans/2,(ans&1?5:0)); }