結果
| 問題 | 
                            No.95 Alice and Graph
                             | 
                    
| コンテスト | |
| ユーザー | 
                             kmjp
                         | 
                    
| 提出日時 | 2014-12-07 20:31:04 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,386 bytes | 
| コンパイル時間 | 1,673 ms | 
| コンパイル使用メモリ | 160,260 KB | 
| 実行使用メモリ | 13,952 KB | 
| 最終ジャッジ日時 | 2024-06-11 16:30:12 | 
| 合計ジャッジ時間 | 14,123 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | TLE * 1 -- * 13 | 
ソースコード
#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;
}
            
            
            
        
            
kmjp