結果

問題 No.19 ステージの選択
ユーザー assy1028assy1028
提出日時 2015-03-21 21:11:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,304 bytes
コンパイル時間 1,197 ms
コンパイル使用メモリ 91,420 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 23:27:50
合計ジャッジ時間 1,763 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef pair<int, int> P;
typedef unsigned int uint;
typedef unsigned long long ull;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};

const int inf = 1000000009;
const int max_v = 110;
int V;
vector<int> G[max_v];
vector<int> rG[max_v];
vector<int> vs;
bool used[max_v];
int cmp[max_v];

void add_edge(int from, int to) {
    G[from].push_back(to);
    rG[to].push_back(from);
}

void dfs(int v) {
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
	if (!used[G[v][i]]) dfs(G[v][i]);
    }
    vs.push_back(v);
}

void rdfs(int v, int k) {
    used[v] = true;
    cmp[v] = k;
    for (int i = 0; i < rG[v].size(); i++) {
	if (!used[rG[v][i]]) rdfs(rG[v][i], k);
    }
}

int scc() {
    memset(used, 0, sizeof(used));
    vs.clear();
    for (int v= 0; v < V; v++) {
	if (!used[v]) dfs(v);
    }
    memset(used, 0, sizeof(used));
    int k = 0;
    for (int i = vs.size() -1; i >= 0; i--) {
	if (!used[vs[i]]) rdfs(vs[i], k++);
    }
    return k;
}

int main() {
    int n;
    scanf("%d", &n);
    V = n;
    int ls[n];
    double res = 0;
    for (int i = 0; i < n; i++) {
	int l, s;
	scanf("%d%d", &l, &s);
	s--;
	add_edge(s, i);
	ls[i] = l;
	res += (double)l / 2;
    }

    int k = scc();
    vector<bool> in(k, false);
    for (int i = 0; i < n; i++) {
	for (int j = 0; j < G[i].size(); j++) {
	    if (cmp[G[i][j]] != cmp[i])
		in[cmp[G[i][j]]] = true;
	}
    }
    for (int i = 0; i < k; i++) {
	if (!in[i]) {
	    int mini = inf;
	    for (int j = 0; j < n; j++)
		if (cmp[j] == i)
		    mini = min(mini, ls[j]);
	    res += (double)mini / 2;
	}
    }

    printf("%.1f\n", floor(res * 10 + 0.5) / 10.0);
}
0