結果

問題 No.848 なかよし旅行
ユーザー tarattata1tarattata1
提出日時 2019-07-05 23:25:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 2,018 bytes
コンパイル時間 960 ms
コンパイル使用メモリ 82,256 KB
実行使用メモリ 8,372 KB
最終ジャッジ日時 2024-04-25 13:50:59
合計ジャッジ時間 2,264 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
8,372 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 16 ms
6,944 KB
testcase_12 AC 21 ms
6,940 KB
testcase_13 AC 27 ms
6,944 KB
testcase_14 AC 11 ms
6,940 KB
testcase_15 AC 25 ms
6,940 KB
testcase_16 AC 41 ms
6,940 KB
testcase_17 AC 28 ms
6,940 KB
testcase_18 AC 16 ms
6,940 KB
testcase_19 AC 15 ms
6,940 KB
testcase_20 AC 8 ms
6,940 KB
testcase_21 AC 34 ms
6,940 KB
testcase_22 AC 33 ms
6,940 KB
testcase_23 AC 18 ms
6,944 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 46 ms
6,940 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 1 ms
6,944 KB
testcase_29 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#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;
}
0