結果

問題 No.95 Alice and Graph
ユーザー yaoshimaxyaoshimax
提出日時 2015-03-08 15:46:38
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,697 bytes
コンパイル時間 1,670 ms
コンパイル使用メモリ 86,580 KB
実行使用メモリ 7,752 KB
最終ジャッジ日時 2023-09-06 21:40:26
合計ジャッジ時間 3,216 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>

using namespace std;

int main(){
   int N,M,K;
   cin >> N >> M >> K;
   int graph[N][N];
   for( int i=0;i<N;i++)for(int j=0;j<N;j++) graph[i][j]=50000;
   for( int i = 0 ; i < M ; i++ ){
      int u,v;
      cin>>u>>v;
      u--;v--;
      graph[u][v]=graph[v][u]=1;
   }
   for(int i=0;i<N;i++)for(int j=0;j<N;j++) for(int k=0;k<N;k++ ){
      graph[j][k]=min(graph[j][i]+graph[i][k],graph[j][k]);
   }
   int stack[K];
   stack[0]=0;
   int size=1;
   for( int n = N-1; n > 0 ; n-- ){
      if(size>=K+1) break;
      stack[size]=n;
      size+=1;
      int dp[1<<size][size];
      memset(dp,50000,sizeof(dp));
      dp[1][0]=0;
      for( int m = 0 ; m<(1<<size); m++ ){
         for(int s=0;s<size;s++ ){
            if( (m&(1<<s))>0 && dp[m][s]<K){
               for( int t=0; t<size; t++){
                  if( (m&(1<<t))==0 ){
                     dp[m|(1<<t)][t]=min(dp[m|(1<<t)][t],dp[m][s]+graph[stack[s]][stack[t]]);
                  }
               }
            }
         }
      }
      bool ok = false;
      for( int e = 0 ; e < size; e++ ){
         if( dp[(1<<size)-1][e] <= K){
            ok=true;
            break;
         }
      }
      if( ok == false ){
         size-=1;
      }
   }
   int ans =0 ;
   for( int i = 0 ; i < size; i++ ){
      ans += (1<<stack[i])-1;
   }
   cout << ans << endl;
   return 0;
}
0