結果

問題 No.19 ステージの選択
ユーザー logxlogx
提出日時 2021-07-24 09:37:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,515 bytes
コンパイル時間 2,125 ms
コンパイル使用メモリ 178,792 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 15:20:32
合計ジャッジ時間 3,762 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#ifdef LOGX
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;

/*---------macro---------*/
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define unless(x) if(!(x))
#define until(x) while(!(x))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define mybit(i,j) (((i)>>(j))&1)

/*---------type/const---------*/
const int big=1000000007;
//const int big=998244353;
const double EPS=1e-8; //適宜変える
typedef long long ll;
typedef unsigned long long ull;
typedef std::string::const_iterator state; //構文解析
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char newl='\n';
struct{
    constexpr operator int(){return -int(1e9)-10;}
    constexpr operator ll(){return -ll(1e18)-10;}
}neginf;
struct{
    constexpr operator int(){return int(1e9)+10;}
    constexpr operator ll(){return ll(1e18)+10;}
    constexpr auto operator -(){return neginf;}
}inf;

/*---------debug---------*/
#ifdef LOGX
#include <template/debug.hpp>
#else
#define dbg(...) ;
#define dbgnewl ;
#define prt(x) ;
#define _prt(x) ;
#endif

/*---------function---------*/
template<typename T> T max(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;}
template<typename T> T min(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;}
template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;}
template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;}
bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);}
template<class T,class U>T expm(T x,U y,const ll mod=big){T res=1;while(y){if(y&1)(res*=x)%=mod;(x*=x)%=mod;y>>=1;}return res;}
template<class T,class U>T exp(T x,U y){T res=1;while(y){if(y&1)res*=x;x*=x;y>>=1;}return res;}


//SCCはおそらくやりすぎ、閉路検出でいい
int main(){
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(1);
/*------------------------------------*/
    
    int n;
    cin >> n;
    vector<vector<int>> g(n),ginv(n);
    vector<int> val(n);
    rep(i,n){
        int s;
        cin >> val[i] >> s;
        s--;
        g[s].emplace_back(i);
        ginv[i].emplace_back(s);
    }
    vector<int> vec;
    vec.reserve(n);
    vector<bool> al(n,false);
    auto dfs=[&](int v,auto &dfs)->void{
        al[v]=true;
        for(int ne:g[v])if(!al[v]){
            dfs(ne,dfs);
        }
        vec.emplace_back(v);
        return;
    };
    rep(i,n)if(!al[i])dfs(i,dfs);

    reverse(ALL(vec));
    al.assign(n,false);
    vector<int> res(n);

    auto dfs2=[&](int v,int now,auto &dfs2)->void{
        al[v]=true;
        res[v]=now;
        for(int ne:ginv[v])if(!al[ne]){
            dfs2(ne,now,dfs2);
        }
    };
    dbg(vec);
    int now=0;
    for(int i:vec)if(!al[i]){
        dbg(i);
        dfs2(i,now++,dfs2);
    }
    dbg(res);

    int sz=now;
    vector<int> ord(sz);//入次数(0以上か否かだけを見れば良い)
    rep(i,n)for(int j:ginv[i]){
        if(res[i]!=res[j])ord[res[i]]++;
    }
    vector<int> add_value(sz,inf);
    rep(i,sz){
        if(ord[i])add_value[i]=0;
    }

    int ans=0;
    rep(i,n){
        ans+=val[i]*5;
        chmin(add_value[res[i]],val[i]);
    }
    dbg(add_value);
    for(int x:add_value)ans+=x*5;
    cout << ans/10.0 << newl;
}
0