結果

問題 No.95 Alice and Graph
ユーザー Ysmr_RyYsmr_Ry
提出日時 2014-12-25 17:57:44
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,199 bytes
コンパイル時間 1,154 ms
コンパイル使用メモリ 47,144 KB
実行使用メモリ 4,912 KB
最終ジャッジ日時 2023-09-03 17:27:15
合計ジャッジ時間 4,294 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 = 1<<29;

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

int main()
{
	scanf( "%d%d%d", &N, &M, &K );
	
	rep( i, N ) rep( j, 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[i]][v[j]] );
	
		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