結果

問題 No.19 ステージの選択
ユーザー Ysmr_RyYsmr_Ry
提出日時 2014-11-11 20:19:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 879 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 27,144 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 23:26:37
合計ジャッジ時間 1,111 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<cstring>
#define rep(i,a) for(int i=0;i<(a);++i)
#define clr(a,v) memset((a),(v),sizeof(a))

const int MAX_N = 100;

int N;
int L[MAX_N], S[MAX_N];
bool used[MAX_N], done[MAX_N];

int dfs( int v, int t )
{
	if( done[S[v]] )
		return -1;
	if( v == t )
		return t;
	if( used[S[v]] )
		return -1;

	used[v] = true;

	int ret = dfs( S[v], t );
	
	if( ret < 0 )
		return -1;
	if( L[v] < L[ret] )
		return v;

	return ret;
}

int main()
{
	scanf( "%d", &N );
	rep( i, N )
		scanf( "%d%d", L+i, S+i ), L[i]<<=1, --S[i];

	int ans = 0;
	rep( i, N ) if( !done[i] )
	{
		clr( used, false );
		int res = dfs( S[i], i );

		if( res >= 0 )
			ans += L[res], done[res] = true;
	}

	rep( i, N ) rep( j, N ) if( done[S[j]] && !done[j] )
		done[j] = true, ans += L[j]>>1;

	printf( "%.1f\n", ans/2.0 );

	return 0;
}
0