結果

問題 No.19 ステージの選択
ユーザー yogi_cgyogi_cg
提出日時 2020-03-30 23:06:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,868 bytes
コンパイル時間 1,831 ms
コンパイル使用メモリ 177,852 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 10:33:17
合計ジャッジ時間 2,992 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0