結果

問題 No.95 Alice and Graph
ユーザー Ysmr_RyYsmr_Ry
提出日時 2014-12-25 18:09:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,663 ms / 5,000 ms
コード長 1,212 bytes
コンパイル時間 553 ms
コンパイル使用メモリ 47,636 KB
実行使用メモリ 7,148 KB
最終ジャッジ日時 2023-08-25 01:43:44
合計ジャッジ時間 6,441 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 483 ms
7,092 KB
testcase_01 AC 72 ms
7,084 KB
testcase_02 AC 72 ms
7,148 KB
testcase_03 AC 14 ms
7,084 KB
testcase_04 AC 736 ms
7,144 KB
testcase_05 AC 573 ms
7,096 KB
testcase_06 AC 710 ms
7,116 KB
testcase_07 AC 72 ms
7,100 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1,663 ms
7,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repd(i,a) for(int i=(a);i>0;--i)
#define clr(a,v) memset((a),(v),sizeof(a))

typedef long long ll;

const int MAX_N = 60, MAX_K = 15, INF = 1000;

int N, M, K;
int mat[MAX_N][MAX_N];
int dp[1<<(MAX_K+1)][MAX_K+1];

int main()
{
	scanf( "%d%d%d", &N, &M, &K );
	
	rep( i, MAX_N ) rep( j, MAX_N )
		mat[i][j] = i==j?0:INF;
	rep( i, M )
	{
		int U, V;
		scanf( "%d%d", &U, &V );
		--U; --V;
		mat[U][V] = mat[V][U] = 1;
	}

	rep( k, N ) rep( i, N ) rep( j, N )
		mat[i][j] = std::min( mat[i][j], mat[i][k]+mat[k][j] );

	std::vector<int> v;
	v.push_back(0);

	ll ans = 0;
	repd( i, N-1 )
	{
		if( v.size() >= K+1 )
			break;

		v.push_back(i);
		clr( dp, 0x3f );
		dp[1][0] = 0;
		repi( S, 1, 1<<v.size() ) rep( i, v.size() ) if( !(S>>i&1) ) rep( j, v.size() ) if( i != j && S>>j&1 )
			dp[S|1<<i][i] = std::min( dp[S|1<<i][i], dp[S][j]+mat[v[j]][v[i]] );
	
		bool fl = false;
		rep( j, v.size() ) if( dp[(1<<v.size())-1][j] <= K )
		{ fl = true; break; }
		
		if( !fl )
			v.pop_back();
		else
			ans += (1ll<<i)-1;
	}
	
	printf( "%lld\n", ans );

	return 0;
}
0