結果

問題 No.95 Alice and Graph
ユーザー 沙耶花沙耶花
提出日時 2021-10-23 17:48:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,535 ms / 5,000 ms
コード長 1,198 bytes
コンパイル時間 4,876 ms
コンパイル使用メモリ 267,912 KB
実行使用メモリ 10,152 KB
最終ジャッジ日時 2023-10-26 01:00:24
合計ジャッジ時間 11,940 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 508 ms
10,152 KB
testcase_01 AC 1,527 ms
10,152 KB
testcase_02 AC 1,535 ms
10,152 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 303 ms
7,032 KB
testcase_05 AC 244 ms
7,032 KB
testcase_06 AC 319 ms
10,024 KB
testcase_07 AC 1,389 ms
10,148 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 396 ms
7,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001
int N,M,K;
vector<vector<int>> d;
bool check(vector<int> t){
	int n = t.size();
	vector dp(1<<n,vector<int>(n,Inf));
	rep(i,t.size()){
		dp[1<<i][i] = d[0][t[i]];
	}
	
	rep(i,1<<n){
		rep(j,n){
			if(dp[i][j]==Inf)continue;
			rep(k,n){
				if((i>>k)&1)continue;
				dp[i|(1<<k)][k] = min(dp[i|(1<<k)][k], dp[i][j] + d[t[j]][t[k]]);
			}
		}
	}
	
	int ret = Inf;
	rep(i,n)ret = min(ret,dp.back()[i]);
	return ret <= K;
	
}

int main(){
	
	
	cin>>N>>M>>K;
	d.resize(N,vector<int>(N,Inf));
	vector<vector<int>> E(N);
	rep(i,M){
		int u,v;
		cin>>u>>v;
		u--;v--;
		d[u][v] = 1;
		d[v][u] = 1;
	}
	rep(i,N)d[i][i] = 0;
	
	rep(i,N){
		rep(j,N){
			rep(k,N){
				d[j][k] = min(d[j][k],d[j][i] + d[i][k]);
			}
		}
	}
	
	vector<int> cur;
	for(int i=N-1;i>=0;i--){
		auto temp = cur;
		temp.push_back(i);
		if(check(temp)){
			
		}
		else{
			temp.pop_back();
		}
		swap(cur,temp);
	}
	
	long long ans = 0LL;
	rep(i,cur.size()){
		ans += (1LL<<cur[i])-1LL;
	}
	cout<<ans<<endl;
	
	return 0;
}
0