Submission #42938


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// -YDK- {{{
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <numeric>
#include <string>
#include <cstdio>
#include <vector>
#include <tuple>
#include <cmath>
#include <queue>
#include <regex>
#include <set>
#include <map>
using namespace std;
#define eb emplace_back
#define emp emplace
#define fi first
#define se second
#define debug(...) fprintf(stderr, __VA_ARGS__ )
#define outl(x) cout << (x) << '\n'
#define outl2(x,y) cout << (x) << ' ' << (y) << '\n'
#define endl '\n'
#define rep(i,n) for(int i=0; i<(int)(n); ++i)
#define ALL(x) x.begin(), x.end()
#define YES(f,y,n) cout << ((f)? (#y):(#n)) << '\n'
#define ODD(n) ((n)&1)
#define EVEN(n) (!ODD(n))
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
template<class T>using MaxHeap = priority_queue< T, vector<T>, greater<T> >;
using ll = long long;
using pii = pair<int, int>;
using byte= unsigned char;
inline bool inside(int x, int y, int W, int H) { return x>=0 && y>=0 && x<W && y<H; }
static constexpr int INF = 0x3f3f3f3f;
static constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr int dx[] = {1, 0, -1, 0};
static constexpr int dy[] = {0, 1, 0, -1};
// }}}
#define LIM 12
int N, M, S;
int G[LIM][LIM];
int dp[LIM][1<<LIM];
int slv(int u, int bit)
{
if (~dp[u][bit]) return dp[u][bit];
if (u==S && bit==(1<<N)-1) return 0;
int ret = INF;
rep(i, N) {
if (bit>>i & 1) continue;
chmin(ret, slv(i, bit | (1 << i)) + G[u][i]);
}
return dp[u][bit] = ret;
}
signed main(void)
{
cin.tie(nullptr), ios::sync_with_stdio(false);
memset(G, INF, sizeof(G));
rep(i, LIM) G[i][i] = 0;
cin >> N >> M >> S; --S;
rep(i, M) {
int a, b, c;
cin >> a >> b >> c;
--a, --b;
G[a][b] = G[b][a] = c;
}
rep(k,N) rep(i,N) rep(j,N) chmin(G[i][j], G[i][k] + G[k][j]);
memset(dp, -1, sizeof(dp));
outl( slv(S, 0) );
return 0;
}

ステータス

項目 データ
問題 0010 - クッキー
ユーザー名 Arumakan_ei1727
投稿日時 2018-09-10 18:24:22
言語 C++17
状態 Accepted
得点 35
ソースコード長 2177 Byte
最大実行時間 26 ms
最大メモリ使用量 648 KB

セット

セット 得点 Cases
1 小課題1 5 / 5 cookies_input1.txt
2 小課題2 10 / 10 cookies_input2.txt
3 小課題3 20 / 20 cookies_input3.txt

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
cookies_input1.txt AC 21 ms 604 KB
1
cookies_input2.txt AC 20 ms 624 KB
2
cookies_input3.txt AC 26 ms 648 KB
3