結果

問題 No.95 Alice and Graph
ユーザー assy1028assy1028
提出日時 2016-12-15 18:54:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,585 ms / 5,000 ms
コード長 2,697 bytes
コンパイル時間 922 ms
コンパイル使用メモリ 101,312 KB
実行使用メモリ 12,336 KB
最終ジャッジ日時 2023-08-20 07:38:32
合計ジャッジ時間 9,068 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 507 ms
12,132 KB
testcase_01 AC 1,585 ms
12,076 KB
testcase_02 AC 1,582 ms
12,072 KB
testcase_03 AC 72 ms
12,076 KB
testcase_04 AC 381 ms
12,112 KB
testcase_05 AC 310 ms
12,128 KB
testcase_06 AC 371 ms
12,100 KB
testcase_07 AC 1,441 ms
12,336 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 769 ms
12,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m, k;
int u[66*33], v[66*33];

int d[66][66];
int dp[1<<17][17];

void warshall_floyd() {
    for (int k = 0; k < n; k++)
	for (int i = 0; i < n; i++)
	    for (int j = 0; j < n; j++)
		d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

ll solve() {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            d[i][j] = inf;
        }
        d[i][i] = 0;
    }
    for (int i = 0; i < m; i++) {
        d[u[i]][v[i]] = d[v[i]][u[i]] = 1;
    }
    warshall_floyd();

    vector<int> vec;
    vec.push_back(0);
    for (int i = n-1; i > 0; i--) {
        vec.push_back(i);
        int l = vec.size();
        for (int j = 0; j < 1<<(k+2); j++) fill(dp[j], dp[j]+k+2, inf);
        dp[0][0] = 0;
        for (int s = 0; s < 1<<l; s++) {
            for (int p = 0; p < l; p++) {
                if ((s>>p)&1) {
                    for (int q = 0; q < l; q++) {
                        dp[s][p] = min(dp[s][p], dp[s^(1<<p)][q] + d[vec[q]][vec[p]]);
                    }
                }
            }
        }
        bool flag = false;
        for (int j = 0; j < l; j++) {
            if (dp[(1<<l)-1][j] <= k) {
                flag = true;
                break;
            }
        }
        if (!flag) vec.pop_back();
    }
    
    ll res = 0;
    for (int i = 0; i < vec.size(); i++) {
        res += (1LL<<vec[i]) - 1;
    }
    return res;
}

void input() {
    cin >> n >> m >> k;
    for (int i = 0; i < m; i++) {
        cin >> u[i] >> v[i];
        u[i]--; v[i]--;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}
0