結果
問題 | No.95 Alice and Graph |
ユーザー |
|
提出日時 | 2014-12-07 21:00:16 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 298 ms / 5,000 ms |
コード長 | 1,504 bytes |
コンパイル時間 | 1,322 ms |
コンパイル使用メモリ | 164,132 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-14 13:28:07 |
合計ジャッジ時間 | 3,319 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 |
ソースコード
#include <bits/stdc++.h>#define REP(i,n) for(int i=0; i<(int)(n); ++i)using namespace std;typedef long long LL;const int INF = 1e9;int main(){int N, M, K;cin >> N >> M >> K;int d[60][60] = {};REP(i, N) REP(j, N) d[i][j] = (i == j ? 0 : INF);REP(i, M) {int a, b;cin >> a >> b;a--; b--;d[a][b] = d[b][a] = 1;}REP(k, N) REP(i, N) REP(j, N) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);vector<int> seq;int dp[1 << 15][15];for(int k = N - 1; k > 0; k--) if(d[0][k] <= K) {if(seq.size() == K) break;vector<int> w = seq;w.push_back(k);int L = w.size();REP(s, 1 << L) REP(i, L) dp[s][i] = INF;REP(i, w.size()) {dp[1 << i][i] = d[0][w[i]];}REP(s, 1 << L) REP(i, L) {int u = w[i];REP(j, L) if(!(s >> j & 1)) {int v = w[j];int ns = s | (1 << j);if(d[u][v] == INF) continue;int nd = dp[s][i] + d[u][v];dp[ns][j] = min(dp[ns][j], nd);}}int check = K + 1;REP(i, L) check = min(check, dp[(1 << L) - 1][i]);if(check <= K) {seq = w;} else {continue;}}long long ans = 0;for(int k : seq) {ans += (1LL << k) - 1;}cout << ans << endl;return 0;}