結果
| 問題 |
No.19 ステージの選択
|
| コンテスト | |
| ユーザー |
yogi_cg
|
| 提出日時 | 2020-03-30 23:06:20 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,868 bytes |
| コンパイル時間 | 1,698 ms |
| コンパイル使用メモリ | 179,372 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-23 06:18:28 |
| 合計ジャッジ時間 | 2,589 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 |
ソースコード
#include <bits/stdc++.h>
#define int long long
#define double long double
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;
const int INF = 1e16;
const int MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
vi node;
int root(int x)
{
if(node[x] == x) return x;
return node[x] = root(node[x]);
}
void unite(int x, int y)
{
int rx = root(x);
int ry = root(y);
node[rx] = ry;
}
signed main()
{
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(1);
int N; cin >> N;
vector<pair<double, pair<int, int>>> s(N+1);
s[0].fi = INF;
vd L(N+1);
REPS(i, N)
{
cin >> L[i];
int to; cin >> to;
s[i].fi = L[i];
s[i].se = mp(to, i);
}
sort(ALL(s), greater<>());
#ifdef DEBUG
cout << endl;
REPS(i, N) cout << s[i].se.fi << " " << s[i].se.se << endl;
cout << endl;
#endif
node.resize(N+1); REPS(i, N) node[i] = i;
REPS(i, N)
{
if(root(s[i].se.fi) == s[i].se.se) continue;
unite(s[i].se.se, s[i].se.fi);
}
#ifdef DEBUG
REPS(i, N) cout << root(i) << " ";
cout << endl;
#endif
double ans = 0;
REPS(i, N)
{
if(root(i) == i) ans += L[i];
else ans += L[i]/2;
}
cout << ans << endl;
}
yogi_cg