結果

問題 No.95 Alice and Graph
ユーザー nodchipnodchip
提出日時 2014-12-07 21:21:41
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 3,451 bytes
コンパイル時間 1,316 ms
コンパイル使用メモリ 112,264 KB
実行使用メモリ 16,528 KB
最終ジャッジ日時 2023-09-02 10:38:45
合計ジャッジ時間 5,195 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <iterator>
#include <locale>
#include <memory>
#include <stdexcept>
#include <utility>
#include <string>
#include <fstream>
#include <ios>
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <streambuf>
#include <complex>
#include <numeric>
#include <valarray>
#include <exception>
#include <limits>
#include <new>
#include <typeinfo>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdlib>
#include <cstddef>
#include <cstdarg>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <cwchar>
#include <cwctype>
using namespace std;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
typedef long long ll;
typedef unsigned long long ull;

#define ALL(c) (c).begin(), (c).end()
#define CLEAR(v) memset(v,0,sizeof(v))
#define MP(a,b) make_pair((a),(b))
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ABS(a) ((a)>0?(a):-(a))
template<class T> T MIN(const T& a, const T& b) { return a < b ? a : b; }
template<class T> T MAX(const T& a, const T& b) { return a > b ? a : b; }
template<class T> void MIN_UPDATE(T& a, const T& b) { if (a > b) a = b; }
template<class T> void MAX_UPDATE(T& a, const T& b) { if (a < b) a = b; }

int graph[64][64];
ll best = 0;
vector<int> bestUsed(64);
int K;

bool canGo(const vector<int>& path) {
	ll sum = 0;
	for (int i = 0; i + 1 < path.size(); ++i) {
		sum += graph[path[i]][path[i + 1]];
	}
	return sum <= K;
}

void dfs(int k, vector<int>& path, ll temp, vector<int>& used) {
	if (best < temp) {
		best = temp;
		bestUsed = used;
	}

	if (k == 1) {
		return;
	}

	for (int insertIndex = 1; insertIndex <= path.size(); ++insertIndex) {
		path.insert(path.begin() + insertIndex, k);
		if (canGo(path)) {
			used[k] = true;
			dfs(k - 1, path, temp + (1LL << (k - 1)) - 1, used);
			used[k] = false;
		}
		path.erase(path.begin() + insertIndex);
	}

	if (!bestUsed[k]) {
		dfs(k - 1, path, temp, used);
	}
}

const int PRUNING_THRESHOLD = 1 << 16;

int main() {
	std::ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M >> K;
	REP(i, 64) REP(j, 64) {
		graph[i][j] = INT_MAX / 3;
	}
	REP(m, M) {
		int u, v;
		cin >> u >> v;
		graph[u][v] = 1;
		graph[v][u] = 1;
	}

	REP(k, 64) REP(i, 64) REP(j, 64) {
		MIN_UPDATE(graph[i][j], graph[i][k] + graph[k][j]);
	}

	vector<int> initial;
	initial.push_back(1);
	
	vector<vector<int> > q;
	q.push_back(initial);
	for (int n = N; n > 1; --n) {
		vector<vector<int> > next;
		for (auto path : q) {
			for (int insertIndex = 1; insertIndex <= path.size() && next.size() < PRUNING_THRESHOLD; ++insertIndex) {
				path.insert(path.begin() + insertIndex, n);
				if (canGo(path)) {
					next.push_back(path);
				}
				path.erase(path.begin() + insertIndex);
			}

			if (next.size() == PRUNING_THRESHOLD) {
				break;
			}
		}

		if (!next.empty()) {
			swap(q, next);
		}
	}

	ll answer = 0;
	for (int k : q[0]) {
		answer += (1LL << (k - 1)) - 1;
	}
	cout << answer << endl;
}
0