結果

問題 No.1898 Battle and Exchange
ユーザー milanis48663220milanis48663220
提出日時 2022-04-09 19:28:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 689 ms / 5,000 ms
コード長 3,279 bytes
コンパイル時間 1,476 ms
コンパイル使用メモリ 136,336 KB
実行使用メモリ 14,332 KB
最終ジャッジ日時 2023-08-19 23:29:46
合計ジャッジ時間 19,611 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 37 ms
5,020 KB
testcase_19 AC 72 ms
5,960 KB
testcase_20 AC 47 ms
6,156 KB
testcase_21 AC 192 ms
10,784 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 4 ms
4,380 KB
testcase_29 AC 9 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,384 KB
testcase_32 AC 58 ms
5,752 KB
testcase_33 AC 120 ms
7,492 KB
testcase_34 AC 43 ms
5,164 KB
testcase_35 AC 74 ms
6,420 KB
testcase_36 AC 70 ms
5,924 KB
testcase_37 AC 26 ms
4,448 KB
testcase_38 AC 689 ms
14,332 KB
testcase_39 AC 141 ms
12,644 KB
testcase_40 AC 545 ms
13,592 KB
testcase_41 AC 123 ms
12,004 KB
testcase_42 AC 10 ms
4,376 KB
testcase_43 AC 96 ms
9,388 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 22 ms
4,380 KB
testcase_46 AC 85 ms
6,268 KB
testcase_47 AC 14 ms
4,380 KB
testcase_48 AC 17 ms
4,700 KB
testcase_49 AC 4 ms
4,380 KB
testcase_50 AC 3 ms
4,376 KB
testcase_51 AC 3 ms
4,376 KB
testcase_52 AC 5 ms
4,380 KB
testcase_53 AC 24 ms
5,360 KB
testcase_54 AC 29 ms
5,956 KB
testcase_55 AC 54 ms
5,792 KB
testcase_56 AC 33 ms
6,044 KB
testcase_57 AC 508 ms
11,500 KB
testcase_58 AC 354 ms
11,644 KB
testcase_59 AC 283 ms
11,524 KB
testcase_60 AC 299 ms
11,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(ll n, ll m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(ll n, ll m, ll k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void prll_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(ll i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

using P = pair<ll, ll>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll n, m; cin >> n >> m;
    vector<vector<ll>> g(n);
    for(ll i = 0; i < m; i++){
        ll u, v; cin >> u >> v; u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<ll> a(n), b(n), c(n);
    for(ll i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
        vector<ll> v = {a[i], b[i], c[i]};
        sort(v.begin(), v.end());
        a[i] = v[0];
        b[i] = v[1];
        c[i] = v[2];
    }
    auto ok = [&](ll x) -> bool{
        if(x <= a[0]+b[0]+c[0]) return false;
        priority_queue<ll, vector<ll>, greater<ll>> que;
        ll sum = 0;
        auto push = [&](ll x){
            sum += x;
            que.push(x);
        };
        auto pop = [&](){
            ll x = que.top();
            sum -= x;
            que.pop();
        };
        push(1); 
        push(1); 
        push(x-2);
        push(c[0]);
        pop();
        vector<bool> seen(n);
        seen[0] = true;
        priority_queue<P, vector<P>, greater<P>> que_p;
        bool ok = false;
        for(ll to: g[0]){
            ll s= a[to]+b[to]+c[to];
            if(s < sum) ok = true;
            que_p.push(P(s, to));
            seen[to] = true;
        }
        if(!ok) return false;
        push(a[0]);
        push(b[0]);
        while(que.size() > 3) pop();
        while(!que_p.empty()){
            auto [s, v] = que_p.top(); que_p.pop();
            if(s >= sum) return false;
            if(v == n-1) return true;
            push(a[v]);
            push(b[v]);
            push(c[v]);
            while(que.size() > 3) pop();
            for(ll to: g[v]){
                if(seen[to]) continue;
                ll sum = a[to]+b[to]+c[to];
                que_p.push(P(sum, to));
                seen[to] = true;
            }
        }
        assert(false);
    };
    ll l = 3, r = (3e8)+1;
    while(r-l > 1){
        ll x = (l+r)/2;
        if(ok(x)) r = x;
        else l = x;
    }
    cout << 1 << ' ' << 1 << ' ' << r-2 << endl;
}
0