結果

問題 No.19 ステージの選択
ユーザー iwataiwata
提出日時 2019-12-03 22:29:18
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,087 bytes
コンパイル時間 1,463 ms
コンパイル使用メモリ 159,384 KB
実行使用メモリ 5,268 KB
最終ジャッジ日時 2023-08-18 15:28:57
合計ジャッジ時間 2,610 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

struct Scc{
  int vsize,esize;
  vector<vector<int>> ne,re;
  vector<int> od,cs;
  vector<bool> used;
  Scc(vector<vector<int>>g,int vs,int es):
    vsize(vs),esize(es),ne(g),re(vs),cs(vs,-1),used(vs,false)
  {
    for(int i = 0; i < vsize; ++i){
      for(auto&e:ne[i]){
	re[e].push_back(i);
      }
    }
    for(int i = 0; i < vsize; ++i)dfs(i);
    reverse(od.begin(),od.end());
    int y = 0;
    for(int e:od){
      if(cs[e] != -1)continue;
      rdfs(e,y);
      y++;
    }
  }
  int operator[](int idx){
    return cs[idx];
  }
  void dfs(int x){
    if(used[x]) return;
    used[x] = 1;
    for(auto&e:ne[x])dfs(e);
    od.push_back(x);
  }
  void rdfs(int x,int y){
    if(cs[x] != -1)return;
    cs[x] = y;
    for(auto&e:re[x])rdfs(e,y);
  }
};

int main(){
  int n; cin >> n;
  vector<vector<int>> g(n);
  vector<double> level(n);
  for(int i = 0; i < n; ++i){
    int a,b; cin >> a >> b; b--;
    g[i].push_back(b);
    level[i] = a;
  }
  Scc scc(g,n,n);
  set<int> st;
  double sum = 0;
  for(int i = 0; i < n; ++i){
    int cs = scc.cs[i];
    if(st.count(cs) == 0)sum += level[i];
    else sum += level[i]/2;
    st.insert(scc.cs[g[i][0]]);
  }
  cout << fixed << setprecision(1) << sum << endl;
  return 0;
}
0