Submission #58296
ソースコード
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 | // "header" {{{ #pragma GCC optimize("Ofast") #include <iostream> #include <algorithm> #include <vector> #include <cstring> #include <string> #include <map> #include <unordered_map> #include <queue> #include <stack> #include <deque> #include <set> #include <list> #include <tuple> #include <iomanip> #include <climits> using namespace std; #define rep(i,n) for(int i=0;i<(n);++i) #define reps(i,n) for(int i=1;i<=(n);++i) #define all(x) (x).begin(),(x).end() #define pii pair<int,int> #define int int64_t #define double long double #define Fixed fixed << setprecision(10) #define moke_pair make_pair constexpr int INF = 0x3f3f3f3f; constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr int64_t mod1 = 1000000007; constexpr int64_t mod2 = 998244353; constexpr int dx[] = {1,0,-1,0,1,1,-1,-1}; constexpr int dy[] = {0,-1,0,1,1,-1,-1,1}; template < class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true ); } template < class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true ); } template < class T> using min_heap = priority_queue<T,vector<T>,greater<T> >; template < class T> using max_heap = priority_queue<T>; template < class T, class U> using umap = unordered_map<T,U>; inline int64_t updiv(int64_t n,int64_t d){ return ((n + d -1) / d); } inline int square( int a){ return a * a; } // }}} signed main(){ cin.tie(nullptr); ios_base::sync_with_stdio( false ); int n,m,s; cin >> n >> m >> s; vector<vector< int > > cost(n+1,vector< int >(n+1,INF)); reps(i,m){ int a,b,c; cin >> a >> b >> c; chmin(cost[a][b],c); chmin(cost[b][a],c); } reps(i,n) cost[i][i] = 0; reps(i,n){ reps(j,n){ reps(k,n){ if (cost[i][j] == INF || cost[i][k] == INF) continue ; chmin(cost[j][k],cost[j][i] + cost[i][k]); } } } vector< int > vec; reps(i,n){ if (i != s) vec.emplace_back(i); } int minv = INF; const int vsize = vec.size(); do { int now = s,sum = 0; rep(i,vsize){ sum += cost[now][vec[i]]; now = vec[i]; } chmin(minv,sum + cost[s][vec[vsize-1]]); } while (next_permutation(all(vec))); cout << minv << '\n' ; return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0010 - クッキー |
ユーザー名 | ei1903 |
投稿日時 | 2020-01-28 18:02:31 |
言語 | C++14 |
状態 | Accepted |
得点 | 35 |
ソースコード長 | 2406 Byte |
最大実行時間 | 33 ms |
最大メモリ使用量 | 604 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 | 33 ms | 604 KB |
1
|
||
cookies_input2.txt | AC | 30 ms | 436 KB |
2
|
||
cookies_input3.txt | AC | 28 ms | 516 KB |
3
|