結果

問題 No.95 Alice and Graph
ユーザー chocoruskchocorusk
提出日時 2019-07-07 12:49:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 640 ms / 5,000 ms
コード長 1,800 bytes
コンパイル時間 857 ms
コンパイル使用メモリ 101,992 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-04-15 02:45:36
合計ジャッジ時間 3,163 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 190 ms
7,552 KB
testcase_01 AC 32 ms
7,552 KB
testcase_02 AC 31 ms
7,552 KB
testcase_03 AC 5 ms
7,424 KB
testcase_04 AC 288 ms
7,552 KB
testcase_05 AC 228 ms
7,552 KB
testcase_06 AC 280 ms
7,552 KB
testcase_07 AC 30 ms
7,296 KB
testcase_08 AC 5 ms
7,424 KB
testcase_09 AC 4 ms
7,424 KB
testcase_10 AC 4 ms
7,424 KB
testcase_11 AC 5 ms
7,424 KB
testcase_12 AC 5 ms
7,296 KB
testcase_13 AC 640 ms
7,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF=1e8;
int n, m, k;
int d[66][66];
vector<int> v;
bool check(){
    if(v.size()>k) return false;
    int dp[16][1<<16];
    int l=v.size()+1;
    for(int i=0; i<l; i++) fill(dp[i], dp[i]+(1<<l), INF);
    dp[0][1]=0;
    for(int i=1; i<(1<<l); i+=2){
        for(int j=0; j<l; j++){
            if((i&(1<<j))==0) continue;
            int x;
            if(j==0) x=0;
            else x=v[j-1];
            for(int p=0; p<l; p++){
                if(i&(1<<p)) continue;
                int y=v[p-1];
                dp[p][i^(1<<p)]=min(dp[p][i^(1<<p)], dp[j][i]+d[x][y]);
            }
        }
    }
    for(int i=0; i<l; i++){
        if(dp[i][(1<<l)-1]<=k) return true;
    }
    return false;
}
int main()
{
    cin>>n>>m>>k;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i==j) d[i][j]=0;
            else d[i][j]=INF;
        }
    }
    for(int i=0; i<m; i++){
        int u, v; cin>>u>>v;
        u--; v--;
        d[u][v]=d[v][u]=1;
    }
    for(int l=0; l<n; l++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                d[i][j]=min(d[i][j], d[i][l]+d[l][j]);
            }
        }
    }
    for(int i=n-1; i>=1; i--){
        v.push_back(i);
        if(!check()) v.pop_back();
    }
    ll ans=0;
    for(auto x:v) ans+=((1ll<<x)-1);
    cout<<ans<<endl;
    return 0;
}
0