結果
問題 |
No.19 ステージの選択
|
ユーザー |
|
提出日時 | 2025-09-20 15:14:07 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 689 bytes |
コンパイル時間 | 2,982 ms |
コンパイル使用メモリ | 281,740 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-09-20 15:14:11 |
合計ジャッジ時間 | 4,078 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < n; ++i) int main(void) { int N; cin >> N; vector<int> L(N), S(N); rep(i,N) { cin >> L[i] >> S[i]; --S[i]; } vector<int> d(N, 0); rep(i,N) ++d[S[i]]; queue<int> que; rep(i,N) if(d[i] == 0) que.push(i); while(!que.empty()) { int v = que.front(); que.pop(); --d[S[v]]; if(d[S[v]] == 0) que.push(S[v]); } int ans = 0; rep(i,N) ans += L[i]; rep(i,N) { if(d[i] == 0) continue; int cnt = 1e9, now = i; while(d[now] != 0) { d[now] = 0; cnt = min(cnt, L[now]); now = S[now]; } ans += cnt; } cout << ans / 2 << (ans % 2 == 0 ? ".0" : ".5") << endl; return 0; }