結果
問題 | No.848 なかよし旅行 |
ユーザー | roto_37 |
提出日時 | 2019-07-23 19:37:06 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,127 bytes |
コンパイル時間 | 1,181 ms |
コンパイル使用メモリ | 128,392 KB |
実行使用メモリ | 10,652 KB |
最終ジャッジ日時 | 2024-10-07 02:18:42 |
合計ジャッジ時間 | 2,717 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 86 ms
10,652 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 27 ms
6,400 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 3 ms
5,248 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 1 ms
5,248 KB |
testcase_25 | WA | - |
testcase_26 | AC | 2 ms
5,248 KB |
testcase_27 | AC | 1 ms
5,248 KB |
testcase_28 | AC | 1 ms
5,248 KB |
testcase_29 | AC | 1 ms
5,248 KB |
ソースコード
//#include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <bitset> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <stack> #include <queue> #include <deque> #include <cstring> #include <string> #include <utility> #include <array> #include <complex> #include <valarray> #include <cassert> #include <cmath> #include <functional> #include <iomanip> #include <chrono> #include <random> #include <numeric> #include<memory> using namespace std; #define int long long typedef long long ll; typedef unsigned long long ull; //typedef unsigned __int128 HASH; typedef pair<int,int> pii; typedef pair<ll, ll> pll; typedef pair<ull, ull> pullull; typedef pair<ll,int> plli; typedef pair<double,int> pdi; typedef pair<long double, int> pdbi; typedef pair<int,pii> pipii; typedef pair<ll,pll> plpll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<pii> vpii; typedef vector<vector<int>> mat; #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n);i>0;i--) #define rrep2(i,a,b) for (int i=(a);i>b;i--) #define pb push_back #define fi first #define se second #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() const ll hmod1 = 999999937; const ll hmod2 = 1000000000 + 9; const int INF = 1<<30; const ll INFLL = 1LL<<62; const long double EPS = 1e-12; const ll mod = 1000000000 + 7; //const ll mod = 998244353; const int dx4[4] = {1, 0, -1, 0}; const int dy4[4] = {0, 1, 0, -1}; const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1}; const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1}; const long double pi = 3.141592653589793; #define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod #define inside(y, x, h, w) (0 <= (y) && (y) < (h) && 0 <= (x) && (x) < (w)) ? true : false //debug #define DEBUG #define DUMPOUT cerr #ifdef DEBUG #define dump(...) DUMPOUT<<#__VA_ARGS__<<" :["<<__FUNCTION__<<":"<<__LINE__<<"]"<<endl; DUMPOUT<<" "; dump_func(__VA_ARGS__) #else #define dump(...) #endif void dump_func() {DUMPOUT << endl;}; template <class Head, class... Tail> void dump_func(Head&& head, Tail&&... tail) { DUMPOUT << head; if (sizeof...(Tail) == 0) DUMPOUT << " "; else DUMPOUT << ", "; dump_func(std::move(tail)...); } //ostream template<typename T> ostream& operator << (ostream& os, vector<T>& vec) { os << "["; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "]"; return os; } template<typename T, typename U> ostream& operator << (ostream& os, pair<T, U>& pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } template<typename T, typename U> ostream& operator << (ostream& os, map<T, U>& map_var) { os << "["; for (auto itr = map_var.begin(); itr != map_var.end(); itr++) { os << "(" << itr->first << ", " << itr->second << ")"; itr++; if(itr != map_var.end()) os << ", "; itr--; } os << "]"; return os; } template<typename T> ostream& operator << (ostream& os, set<T>& set_var) { os << "["; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) { os << *itr; ++itr; if(itr != set_var.end()) os << ", "; itr--; } os << "]"; return os; } int n, m, p, q, t; struct edge{int to, cost;}; vector<vector<edge>> g(2000 + 5); vector<ll> dijkstra(int s, int n, vector<vector<edge>>& g){ priority_queue<plli, vector<plli>, greater<plli>> pque; vector<ll> d(n, INFLL); d[s] = 0; pque.push(plli(0, s)); while (!pque.empty()){ plli p = pque.top(); pque.pop(); int fr = p.second; if (d[fr] < p.first) continue; for (edge e: g[fr]){ if (d[e.to] > d[fr] + e.cost){ d[e.to] = d[fr] + e.cost; pque.push(plli(d[e.to], e.to)); } } } return d; } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m >> p >> q >> t; p--; q--; rep(i, m) { int u, v, c; cin >> u >> v >> c; u--; v--; g[u].push_back(edge{v, c}); g[v].push_back(edge{u, c}); } vector<int> d1 = dijkstra(0, n, g); if (2 * d1[p] > t || 2 * d1[q] > t) { cout << -1 << endl; return 0; } vector<int> dp = dijkstra(p, n, g); vector<int> dq = dijkstra(q, n, g); if (d1[p] + dp[q] + dq[0] <= t) { cout << t << endl; return 0; } vector<pair<int, pii>> GO(n); vector<pair<int, pii>> BACK(n); rep(i, n) { GO[i] = {d1[i], {d1[i] + dp[i], d1[i] + dq[i]}}; BACK[i] ={d1[i], {dp[i], dq[i]}}; } int ans = -1; rep(i, n) { if (i == p || i == q) continue; int yuki1 = GO[i].se.fi; int yuki2 = GO[i].se.se; int Same = GO[i].fi; rep(j, n) { if (j == p || j == q) continue; int tmp_yuki1 = yuki1 + BACK[j].se.fi; int tmp_yuki2 = yuki2 + BACK[j].se.se; int tmpT = d1[j] + max(tmp_yuki1, tmp_yuki2); Same += d1[j]; if (tmpT <= t) { ans = max(ans, Same + t - tmpT); } } } cout << ans << endl; }