結果

問題 No.95 Alice and Graph
ユーザー yuustiyuusti
提出日時 2014-12-09 01:43:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,536 ms / 5,000 ms
コード長 2,060 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 92,748 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-26 21:56:08
合計ジャッジ時間 6,134 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 485 ms
11,648 KB
testcase_01 AC 69 ms
11,520 KB
testcase_02 AC 74 ms
11,648 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 703 ms
11,648 KB
testcase_05 AC 552 ms
11,648 KB
testcase_06 AC 730 ms
11,648 KB
testcase_07 AC 73 ms
11,648 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1,536 ms
11,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <climits>
#include <bitset>
#include <cassert>
#include <random>
#include <complex>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int N = 65;
vector<int> G[N];
int d[N][N];

int num[N];
int dp[N][1 << 15];

int idx;
int n, m, k;
int rec(int pos, int x){
	if (!x) return 0;

	int &res = dp[pos][x];
	if (res + 1) return res;
	res = 1e9;

	rep(i, n){
		int nx = x;
		if (num[i] >= 0 && (x >> num[i] & 1)){
			nx &= ~(1 << num[i]);
			res = min(res, d[pos][i] + rec(i, nx));
		}
	}
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> n >> m >> k;

	rep(i, N) rep(j, N) if (i != j) d[i][j] = 1e9;
	rep(i, m){
		int u, v;
		cin >> u >> v;
		--u, --v;
		d[u][v] = d[v][u] = 1;
		G[u].push_back(v);
		G[v].push_back(u);
	}

	rep(i, n) rep(j, n) rep(k, n) d[j][k] = min(d[j][k], d[j][i] + d[i][k]);

	int st = -1;
	for (int i = n - 1; i >= 0; --i){
		if (d[0][i] <= k){
			st = i;
			break;
		}
	}

	ll ans = (1ll << st) - 1;
	idx = 1;
	MEMSET(num, -1);
	num[st] = 0;
	for (int i = st - 1; i >= 1; --i){
		MEMSET(dp, -1);
		num[i] = idx;
		int dist = rec(0, (1 << idx + 1) - 1);
		//cout << dist << endl;
		if (dist <= k){
			++idx;
			ans += (1ll << i) - 1;
			if (idx >= k) break;
		}
		else{
			num[i] = -1;
		}
	}
	cout << ans << endl;

	return 0;
}
0