Submission #59245


ソースコード

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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'
using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;
static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;
const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};
vector<LL> Div(LL n) {
vector<LL> ret;
for(LL i = 1; i * i <= n; ++i) {
if(n % i == 0) {
ret.pb(i);
if(i * i != n) ret.pb(n / i);
}
}
sort(all(ret));
return ret;
}
int graph[15][15];
void WarshallFloyd(int N) {
for( int k = 1; k <= N; ++k ) {
for( int i = 1; i <= N; ++i ) {
for( int j = 1; j <= N; ++j ) {
if( graph[i][k] == INF || graph[k][j] == INF ) {
continue;
}
graph[i][j] = min( graph[i][j],
graph[i][k] + graph[k][j] );
}
}
}
return;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, M, S;
cin >> N >> M >> S;
vector<int> v;
for(int i = 1; i <= N; ++i) {
if(i != S) v.pb(i);
}
for(int i = 0; i < 15; ++i) {
for(int j = 0; j < 15; ++j) {
if(i != j) graph[i][j] = INF;
}
}
while(M--) {
int a, b, c;
cin >> a >> b >> c;
graph[a][b] = graph[b][a] = c;
}
WarshallFloyd(N);
int res = INF;
do {
int cur = S;
int dist = 0;
for(int i = 0; i < v.size(); ++i) {
dist += graph[cur][v[i]];
cur = v[i];
}
res = min(res, dist + graph[cur][S]);
} while(next_permutation(all(v)));
cout << res << endl;
return 0;
}

ステータス

項目 データ
問題 0010 - クッキー
ユーザー名 crom
投稿日時 2020-05-05 03:01:58
言語 C++14
状態 Accepted
得点 35
ソースコード長 2211 Byte
最大実行時間 32 ms
最大メモリ使用量 684 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 32 ms 600 KB
1
cookies_input2.txt AC 23 ms 684 KB
2
cookies_input3.txt AC 24 ms 636 KB
3