結果
問題 | No.17 2つの地点に泊まりたい |
ユーザー | daleksprinter |
提出日時 | 2018-09-24 19:20:27 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,937 bytes |
コンパイル時間 | 1,762 ms |
コンパイル使用メモリ | 177,440 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-22 16:05:02 |
合計ジャッジ時間 | 2,683 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; //macro----------------------------------------------------------------------------------------- #define rep(i,a,b) for(int i=a;i<b;i++) #define revrep(i,a,b) for(int i=a;i>b;i--) #define int long long //constant-------------------------------------------------------------------------------------- const int inf = 100100100100000; const int mod = 1000000007; int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; //general_method-------------------------------------------------------------------------------- vector<int> cs(vector<int> arr){vector<int> ret = arr;rep(i,1,arr.size()){ret[i] += ret[i-1];}return ret;} int ceil(int a, int b){if(a%b == 0) return a/b;else return a/b + 1;} int digitlen(int i){int t = i;int count = 0;while(t){count += 1;t /= 10;}return count;} int gcd(int m, int n){if((0== m)||(0 == n))return 0;while(m != n){if(m > n)m = m - n;else n = n - m;}return m;} int lcm(int n, int m){return n*m/gcd(n,m);} //io_method------------------------------------------------------------------------------------- int input(){int tmp;cin >> tmp;return tmp;} string raw_input(){string tmp;cin >> tmp;return tmp;} string readline(){string s;getline(cin, s);return s;} void print(int n){cout << n << endl;} void print(vector<int> arr){cout << arr[0];rep(i,1,arr.size()) cout << " " << arr[i];cout << endl;} void print(string s){cout << s << endl;} void print(pair<int, int> p){cout << p.first << " " << p.second;} void print(vector<vector<int>> arr){rep(i,0,arr.size()){print(arr[i]);}} //main------------------------------------------------------------------------------------------ int mod_pow(int x, int n, int m){if(n== 0) return 1;int res = mod_pow(x*x%m,n/2,m);if(n&1) res = res*x%m;return res;} int factorial(int x){int res = 1;rep(i,2,x+1){res *= i;res %= mod;}return res;} int inv(int n){return mod_pow(n,mod-2,mod);} vector<vector<int>> warshaint_floyd(vector<vector<int>> edges,int v){ vector<vector<int>> ret = edges; rep(k,0,v){ rep(i,0,v){ rep(j,0,v){ if(ret[i][k] == inf || ret[k][j] == inf) continue; ret[i][j] = min(ret[i][j],ret[i][k] + ret[k][j]); } } } return ret; } signed main(){ std::ios::sync_with_stdio(false); std::cin.tie(0); int n = input(); vector<int> arr; rep(i,0,n) arr.push_back(input()); vector<vector<int> > edges(n,vector<int>(n,inf)); rep(i,0,n) edges[i][i] = 0; print(arr); int m = input(); rep(i,0,m){ int frm, to, cost; cin >> frm >> to >> cost; edges[frm][to] = cost; edges[to][frm] = cost; } edges = warshaint_floyd(edges, n); print(edges); int ans = inf; rep(i,1,n-1){ rep(j,1,n-1){ if(i != j){ ans = min(ans, edges[0][i] + arr[i] + edges[i][j] + arr[j] + edges[j][n-1]); } } } print(ans); }