結果
問題 | No.95 Alice and Graph |
ユーザー |
![]() |
提出日時 | 2014-12-07 20:16:27 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 965 ms / 5,000 ms |
コード長 | 1,602 bytes |
コンパイル時間 | 856 ms |
コンパイル使用メモリ | 66,072 KB |
実行使用メモリ | 7,772 KB |
最終ジャッジ日時 | 2024-11-14 13:26:56 |
合計ジャッジ時間 | 4,426 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 |
コンパイルメッセージ
main.cpp: In function ‘void init()’: main.cpp:23:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 23 | scanf("%d%d%d", &N, &M, &K); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:27:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | scanf("%d%d", &x, &y); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include<cstdio>#include<iostream>#include<vector>#include<algorithm>#include<string>#include<cstring>using namespace std;typedef long long LL;typedef vector<int> VI;#define REP(i,n) for(int i=0; i<int(n); i++)#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)template<class T> inline T &amin(T &a, T b) { if (a>b) a=b; return a; }template<class T> inline T &amax(T &a, T b) { if (a<b) a=b; return a; }int N, M, K;int FW[60][60];void init() {scanf("%d%d%d", &N, &M, &K);memset(FW, 0x3f, sizeof FW);REP (i, M) {int x, y;scanf("%d%d", &x, &y);x--; y--;FW[x][y] = FW[y][x] = 1;}REP (i, N) FW[i][i] = 0;}int dp[1<<16][16];int cost(vector<int> v) {int N = v.size();memset(dp, 0x3f, sizeof dp);dp[1][0] = 0;REP (S, 1<<N) {REP (i, N) if (S & (1<<i)) { // fromREP (j, N) {amin(dp[S | (1<<j)][j], dp[S][i] + FW[v[i]][v[j]]);}}}int ans = dp[(1<<N)-1][0];REP (i, N) amin(ans, dp[(1<<N)-1][i]);return ans;}int main() {init();REP (k, N) REP (i, N) REP (j, N) amin(FW[i][j], FW[i][k]+FW[k][j]);// REP (i, N) {// REP (j, N) {// cerr << FW[i][j] << ' ';;// }// cerr << endl;// }vector<int> v(1, 0);for (int i=N-1; i>0; i--) {v.push_back(i);int tmp = cost(v);if (tmp > K) v.pop_back();if (v.size() == 16u) break;}LL ans = 0;REP (i, v.size()) ans += (1LL<<v[i])-1;cout << ans << endl;return 0;}