結果
問題 | No.848 なかよし旅行 |
ユーザー |
![]() |
提出日時 | 2019-07-05 23:25:21 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 96 ms / 2,000 ms |
コード長 | 2,018 bytes |
コンパイル時間 | 872 ms |
コンパイル使用メモリ | 81,996 KB |
実行使用メモリ | 8,372 KB |
最終ジャッジ日時 | 2024-11-08 00:51:49 |
合計ジャッジ時間 | 2,514 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’: main.cpp:52:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 52 | scanf("%d%d%d%d%d", &n, &m, &p, &q, &t); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:59:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 59 | scanf("%d%d%d", &a, &b, &c); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <algorithm> #include <vector> #include <set> #include <map> #include <queue> #include <list> #include <iterator> #include <assert.h> #pragma warning(disable:4996) typedef long long ll; #define MIN(a, b) ((a)>(b)? (b): (a)) #define MAX(a, b) ((a)<(b)? (b): (a)) #define LINF 9223300000000000000 #define INF 2140000000 const long long MOD = 1000000007; using namespace std; //ダイクストラ (ABC035-D) typedef pair<ll,int> P; vector<ll> dijkstra(int s, const vector<vector<pair<int,int> > >& G){ priority_queue< P, vector<P>, greater<P> > que; vector<ll> d(G.size(), LINF); d[s] = 0; que.push(P(0, s)); while(!que.empty()){ int curr = que.top().second; ll dcurr = que.top().first; que.pop(); if(d[curr] < dcurr) continue; int i; for(i=0; i<(int)G[curr].size(); i++){ int next = G[curr][i].first; ll dist = G[curr][i].second; if(d[next] > d[curr] + dist){ d[next] = d[curr] + dist; que.push(P(d[next], next)); } } } return d; } int main(int argc, char* argv[]) { int n,m,p,q,t; scanf("%d%d%d%d%d", &n, &m, &p, &q, &t); p--; q--; vector<vector<pair<int, int> > > g(n); int i,j; for(i=0; i<m; i++) { int a,b,c; scanf("%d%d%d", &a, &b, &c); g[a-1].push_back(make_pair(b-1,c)); g[b-1].push_back(make_pair(a-1,c)); } vector<ll> v0=dijkstra(0, g); vector<ll> v1=dijkstra(p, g); vector<ll> v2=dijkstra(q, g); ll ans=-1; if(v0[p]+v0[q]+v1[q]<=t) { ans = t; } for(i=0; i<n; i++) { for(j=0; j<n; j++) { ll dist=v0[i]+v0[j]+MAX(v1[i]+v1[j],v2[i]+v2[j]); if(dist<=t) { ll val=v0[i]+v0[j]+(t-dist); ans=MAX(ans,val); } } } printf("%lld\n", ans); return 0; }