結果

問題 No.2387 Yokan Factory
ユーザー ococonomy1ococonomy1
提出日時 2023-07-21 21:55:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 565 ms / 5,000 ms
コード長 4,466 bytes
コンパイル時間 1,677 ms
コンパイル使用メモリ 135,628 KB
実行使用メモリ 13,308 KB
最終ジャッジ日時 2023-10-21 21:56:20
合計ジャッジ時間 9,189 ms
ジャッジサーバーID
(参考情報)
judge9 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 300 ms
12,800 KB
testcase_16 AC 206 ms
12,416 KB
testcase_17 AC 397 ms
13,308 KB
testcase_18 AC 505 ms
13,020 KB
testcase_19 AC 386 ms
9,452 KB
testcase_20 AC 269 ms
8,408 KB
testcase_21 AC 565 ms
12,024 KB
testcase_22 AC 279 ms
8,292 KB
testcase_23 AC 452 ms
9,676 KB
testcase_24 AC 284 ms
8,800 KB
testcase_25 AC 253 ms
7,260 KB
testcase_26 AC 513 ms
10,708 KB
testcase_27 AC 565 ms
11,792 KB
testcase_28 AC 4 ms
4,348 KB
testcase_29 AC 6 ms
4,348 KB
testcase_30 AC 5 ms
4,348 KB
testcase_31 AC 4 ms
4,348 KB
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 3 ms
4,348 KB
testcase_34 AC 6 ms
4,348 KB
testcase_35 AC 4 ms
4,348 KB
testcase_36 AC 3 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <climits>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using lg = long long;
using pii = pair<int, int>;
using pll = pair<lg, lg>;
#define TEST cerr << "TEST" << endl
#define AMARI 998244353
// #define AMARI 1000000007
#define TEMOTO ((sizeof(long double) == 16) ? false : true)
#define TIME_LIMIT 1980 * (TEMOTO ? 1 : 1000)
#define el '\n'
#define El '\n'
#define mpr make_pair
#define LLINF LLONG_MAX

//ダイクストラ
//引数はグラフのvectorと始点となるノード
// ただしグラフのvectorの中身はg[i][j] = {c,t}の時、点iから出ているj番目の矢印は、コストcでtへ向かうという意味
// pairのfirstがコストなので注意!!!!
// {他のノードへの距離を入れたvector,経路復元において1個前はどこに戻るか}を返す関数
//s→始点となるノード
pair<vector<long long>, vector<int>> ococo_dijkstra(vector<vector<pair<long long, int>>> const& g, int s) {
    vector<long long> distance(g.size(), LLINF);
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> que;
    que.emplace(0, s);
    vector<bool> visited(g.size(), false);
    distance[s] = 0;
    vector<int> prev(g.size(), -1);
    prev[s] = s;

    while (!que.empty()) {
        int karis = que.top().second;
        que.pop();
        if (!visited[karis]) {
            for (int i = 0; i < g[karis].size(); i++) {
                if (distance[g[karis][i].second] > distance[karis] + g[karis][i].first) {
                    distance[g[karis][i].second] = distance[karis] + g[karis][i].first;
                    que.emplace(distance[g[karis][i].second], g[karis][i].second);
                    prev[g[karis][i].second] = karis;
                }
            }
        }
        visited[karis] = true;
    }
    pair<vector<long long>, vector<int>> ans;
    ans.first = distance;
    ans.second = prev;
    return ans;
}


bool func(vector<vector<pair<long long,int>>> const& g,lg x, lg c){
    pair<vector<long long>, vector<int>> temp = ococo_dijkstra(g,0);
    //cerr << temp.first[g.size() - 1] << El;
    if(temp.first[g.size() - 1] <= x){
        //cerr << c << " true" << El;
        return true;
    }
    else{
        //cerr << c << " false" << el;
        return false;
    }
}

#define MULTI_TEST_CASE false
void solve(void) {
    int n,m;
    lg x;
    cin >> n >> m >> x;
    //長さがxを超えないもので一番太いやつ
    //{haba,nagasa,u,v}
    vector<pair<lg,pair<lg,pii>>> edge(m);
    for(int i = 0; i < m; i++){
        cin >> edge[i].second.second.first >> edge[i].second.second.second >> edge[i].second.first >> edge[i].first;
        edge[i].second.second.first--;
        edge[i].second.second.second--;
    }
    sort(edge.rbegin(),edge.rend());
    //答えの幅は[l,r]の中にある
    lg l = 0,r = 1000000001;
    while(r - l >= 2){
        lg c = (l + r) / 2;
        vector<vector<pair<long long,int>>> g(n);
        for(int i = 0; i < m; i++){
            //cerr << edge[i].first << ' ' << c << El;
            if(edge[i].first < c)break;
            g[edge[i].second.second.first].push_back(mpr(edge[i].second.first,edge[i].second.second.second));
            g[edge[i].second.second.second].push_back(mpr(edge[i].second.first,edge[i].second.second.first));
        }
        if(func(g,x,c))l = c;
        else r = c - 1;
    }
    lg ans = -1;
    for(lg c = l; c <= r; c++){
        //cerr << c << el;
        vector<vector<pair<lg,int>>> g(n);
        for(int i = 0; i < m; i++){
            if(edge[i].first < c)break;
            g[edge[i].second.second.first].push_back(mpr(edge[i].second.first,edge[i].second.second.second));
            g[edge[i].second.second.second].push_back(mpr(edge[i].second.first,edge[i].second.second.first));
        }
        //cerr << c << el;
        if(func(g,x,c))ans = c;
        else break;
    }
    cout << ans << el;
    return;
}

void calc(void) {
    return;
}

int main(void) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    calc();
    int t = 1;
    if (MULTI_TEST_CASE) cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
0