結果

問題 No.2387 Yokan Factory
ユーザー soto800soto800
提出日時 2023-07-21 21:40:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 523 ms / 5,000 ms
コード長 2,884 bytes
コンパイル時間 1,844 ms
コンパイル使用メモリ 182,604 KB
実行使用メモリ 12,480 KB
最終ジャッジ日時 2023-10-21 21:36:13
合計ジャッジ時間 7,557 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 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 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 258 ms
12,480 KB
testcase_16 AC 171 ms
11,980 KB
testcase_17 AC 356 ms
12,268 KB
testcase_18 AC 334 ms
11,168 KB
testcase_19 AC 301 ms
9,164 KB
testcase_20 AC 272 ms
8,588 KB
testcase_21 AC 523 ms
10,696 KB
testcase_22 AC 252 ms
8,084 KB
testcase_23 AC 334 ms
9,124 KB
testcase_24 AC 164 ms
8,508 KB
testcase_25 AC 190 ms
6,736 KB
testcase_26 AC 412 ms
9,816 KB
testcase_27 AC 486 ms
10,528 KB
testcase_28 AC 4 ms
4,348 KB
testcase_29 AC 5 ms
4,348 KB
testcase_30 AC 4 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 4 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 #

#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
 
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
struct Edge {
    long long to;
    long long cost;
    long long width;
};
using Graph = vector<vector<Edge>>;
using P = pair<long, int>;
const long long INF = 1LL << 60;
/* dijkstra(G,s,dis)
    入力:グラフ G, 開始点 s, 距離を格納する dis
    計算量:O(|E|log|V|)
    副作用:dis が書き換えられる
*/
void dijkstra(const Graph &G, int s, vector<long long> &dis,lli targetWidth) {
    int N = G.size();
    dis.resize(N, INF);
    priority_queue<P, vector<P>, greater<P>> pq;  // 「仮の最短距離, 頂点」が小さい順に並ぶ
    dis[s] = 0;
    pq.emplace(dis[s], s);
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (dis[v] < p.first) {  // 最短距離で無ければ無視
            continue;
        }
        for (auto &e : G[v]) {
            if (dis[e.to] > dis[v] + e.cost && targetWidth <= e.width) {  // 最短距離候補なら priority_queue に追加
                dis[e.to] = dis[v] + e.cost;
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
}
void solve(){

    lli N,M,X;
    cin>>N>>M>>X;

    Graph graph;

    graph.resize(N);
    REP(i,0,M){
        lli u,v,a,b;
        cin>>u>>v>>a>>b;
        u--;
        v--;
        graph[u].push_back({v,a,b});
        graph[v].push_back({u,a,b});
    }

    lli small = -1,large = 10000000000+10;

    while(small+1 < large){
        vector<lli> dist(N,INF);
        lli middle = (small+large)/2;
        dijkstra(graph,0,dist,middle);

        if(dist[N-1] > X){
            large = middle;
        }
        else{
            small = middle;
        }
    }
    cout<<small<<endl;

}

// Generated by 2.11.0 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){

    lli n;
    //cin>>n;
    n=1;
    std::random_device seed_gen;
    std::mt19937 engine(seed_gen());
    while(n--)solve();
    return 0;
}
0