結果

問題 No.95 Alice and Graph
ユーザー 👑 kmjpkmjp
提出日時 2014-12-07 20:31:04
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,386 bytes
コンパイル時間 1,194 ms
コンパイル使用メモリ 146,892 KB
実行使用メモリ 11,924 KB
最終ジャッジ日時 2023-09-02 09:45:01
合計ジャッジ時間 13,865 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
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 <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M,K;
int mat[100][100];

bool avail(int cur,ll mask,int le) {
	int i;
	if(mask==0) return true;
	if(__builtin_popcount(mask)>le) return false;
	
	FOR(i,N) if((mask&(1LL<<i)) && mat[cur][i]<=le) {
		if(avail(i,mask ^ (1LL<<i),le-mat[cur][i])) return true;
	}
	return false;
	
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>K;
	FOR(x,100) FOR(y,100) mat[x][y]=1000;
	FOR(x,100) mat[x][x]=0;
	FOR(i,M) {
		cin>>x>>y;
		mat[x-1][y-1]=mat[y-1][x-1]=1;
	}
	FOR(i,N) FOR(x,N) FOR(y,N) mat[x][y]=min(mat[x][y],mat[x][i]+mat[i][y]);
	
	
	ll mask=0;
	for(i=N-1;i>0;i--) if(avail(0,mask|(1LL<<i),K)) mask |= 1LL<<i;
	
	ll ret=0;
	FOR(i,N) if(mask & (1LL<<i)) ret += (1LL<<i)-1;
	cout << ret << endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0