結果

問題 No.95 Alice and Graph
ユーザー Ysmr_RyYsmr_Ry
提出日時 2014-12-25 18:02:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,203 bytes
コンパイル時間 498 ms
コンパイル使用メモリ 47,572 KB
実行使用メモリ 6,908 KB
最終ジャッジ日時 2023-09-03 17:27:21
合計ジャッジ時間 2,576 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 65 ms
6,892 KB
testcase_02 AC 64 ms
6,812 KB
testcase_03 AC 13 ms
6,844 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 61 ms
6,832 KB
testcase_08 AC 2 ms
4,376 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 2 ms
4,376 KB
testcase_13 WA -
権限があれば一括ダウンロードができます

ソースコード

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+1)][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