結果

問題 No.19 ステージの選択
ユーザー face4face4
提出日時 2019-11-24 09:01:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,348 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 76,712 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-02 09:24:29
合計ジャッジ時間 2,413 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<numeric>
using namespace std;

vector<int> v[100], rev[100], vs, par(100);
vector<bool> used(100);

void dfs(int x){
    used[x] = true;
    for(int next : v[x]){
        if(!used[next]) dfs(next);
    }
    vs.push_back(x);    // postorder
}

void rdfs(int x, int k){
    used[x] = true;
    par[x] = k;
    for(int next : rev[x]){
        if(!used[next]) rdfs(next, k);
    }
}

int main(){
    int n;
    cin >> n;
    vector<double> score(n);
    for(int i = 0; i < n; i++){
        int s;
        cin >> score[i] >> s;
        s--;
        v[s].push_back(i);
        rev[i].push_back(s);
    }
    fill(used.begin(), used.end(), 0);
    for(int i = 0; i < n; i++){
        if(!used[i])    dfs(i);
    }
    fill(used.begin(), used.end(), 0);
    int comp = 0;
    for(int i = n-1; i >= 0; i--){
        if(!used[vs[i]])    rdfs(vs[i], comp++);
    }
    double ans = accumulate(score.begin(), score.end(), 0) / 2.0;
    for(int i = 0; i < comp; i++){
        bool in = false;
        double mi = 1e9;
        for(int j = 0; j < n; j++){
            if(par[j] != i) continue;
            mi = min(mi, score[j]);
            for(int k : rev[j]){
                in |= par[k] != i;
            }
        }
        if(in)  continue;
        ans += mi/2;
    }
    printf("%.1f\n", ans);
    return 0;
}
0