結果

問題 No.95 Alice and Graph
ユーザー 沙耶花沙耶花
提出日時 2021-10-23 17:39:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,229 bytes
コンパイル時間 4,962 ms
コンパイル使用メモリ 268,268 KB
実行使用メモリ 54,236 KB
最終ジャッジ日時 2023-10-26 00:51:19
合計ジャッジ時間 20,954 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;

bool check(vector<vector<int>> &E,vector<int> t){
	vector<int> ind(N,-1);
	rep(i,t.size()){
		ind[t[i]] = i;
	}
	
	int n = t.size();
	
	vector dis(1<<n,vector<int>(N,Inf));
	dis[0][0] = 0;
	queue<pair<int,int>> Q;
	Q.emplace(0,0);
	
	while(Q.size()>0){
		int x = Q.front().first,y = Q.front().second;
		Q.pop();
		rep(i,E[y].size()){
			int ny = E[y][i];
			int nx = x;
			if(ind[ny]!=-1)nx |= 1<<(ind[ny]);
			if(dis[nx][ny]==Inf){
				dis[nx][ny] = dis[x][y]+1;
				Q.emplace(nx,ny);
			}
		}
	}
	
	int ret = Inf;
	rep(i,N)ret = min(ret,dis.back()[i]);
	return ret <= K;
	
}

int main(){
	
	
	cin>>N>>M>>K;
	
	vector<vector<int>> E(N);
	rep(i,M){
		int u,v;
		cin>>u>>v;
		u--;v--;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	
	vector<int> cur;
	for(int i=N-1;i>=0;i--){
		auto temp = cur;
		temp.push_back(i);
		if(check(E,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