結果
問題 | No.19 ステージの選択 |
ユーザー |
|
提出日時 | 2020-01-04 00:41:33 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 771 bytes |
コンパイル時間 | 1,768 ms |
コンパイル使用メモリ | 174,684 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-22 19:55:29 |
合計ジャッジ時間 | 2,684 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i=0;i<(n);i++)using namespace std;const int INF=1<<29;vector<vector<int>> find_cycles(const vector<int>& f){int n=f.size();vector<vector<int>> Res;vector<int> color(n,-1);rep(u,n) if(color[u]==-1) {int v=u;do{ color[v]=u; v=f[v]; }while(color[v]==-1);if(color[v]==u){vector<int> C;int w=v;do{ C.emplace_back(v); v=f[v]; }while(v!=w);Res.emplace_back(C);}}return Res;}int main(){int n; scanf("%d",&n);vector<int> cost(n),to(n);rep(u,n) scanf("%d%d",&cost[u],&to[u]), to[u]--;double ans=accumulate(cost.begin(),cost.end(),0)/2.0;for(auto C:find_cycles(to)){int mn=INF;for(int u:C) mn=min(mn,cost[u]);ans+=mn/2.0;}printf("%.1f\n",ans);return 0;}