結果

問題 No.2387 Yokan Factory
ユーザー nemutainemutai
提出日時 2023-07-21 22:02:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,194 ms / 5,000 ms
コード長 2,022 bytes
コンパイル時間 2,333 ms
コンパイル使用メモリ 220,904 KB
実行使用メモリ 26,244 KB
最終ジャッジ日時 2023-10-21 22:03:19
合計ジャッジ時間 20,910 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 1 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 885 ms
26,228 KB
testcase_16 AC 629 ms
25,864 KB
testcase_17 AC 1,241 ms
26,244 KB
testcase_18 AC 1,265 ms
22,368 KB
testcase_19 AC 1,459 ms
17,100 KB
testcase_20 AC 1,246 ms
15,788 KB
testcase_21 AC 2,194 ms
21,324 KB
testcase_22 AC 1,127 ms
14,648 KB
testcase_23 AC 1,582 ms
16,976 KB
testcase_24 AC 649 ms
15,460 KB
testcase_25 AC 821 ms
11,264 KB
testcase_26 AC 1,854 ms
18,960 KB
testcase_27 AC 2,157 ms
20,708 KB
testcase_28 AC 6 ms
4,348 KB
testcase_29 AC 11 ms
4,348 KB
testcase_30 AC 7 ms
4,348 KB
testcase_31 AC 6 ms
4,348 KB
testcase_32 AC 4 ms
4,348 KB
testcase_33 AC 5 ms
4,348 KB
testcase_34 AC 9 ms
4,348 KB
testcase_35 AC 7 ms
4,348 KB
testcase_36 AC 4 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define all(v) v.begin(),v.end()
using ll = long long;
using ull = unsigned long long;
using vll=vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,ll>;
using vp=vector<pair<ll, ll>>;

const ll INF=1ll<<60;
ll mod10=1e9+7;
ll mod99=998244353;
const double PI = acos(-1);

#define rep(i,n) for (ll i=0;i<n;++i)
#define per(i,n) for(ll i=n-1;i>=0;--i)
#define rep2(i,a,n) for (ll i=a;i<n;++i)
#define per2(i,a,n) for (ll i=a;i>=n;--i)

template <typename T>
bool chmax(T &a,const T& b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a,const T& b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}

void makeab(ll M,vector<vector<pair<long long,long long>>>& ab,map<tuple<ll,ll,ll>,ll>& mp){
    for(int i=0;i<M;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        ab[a].emplace_back(c,b);
        ab[b].emplace_back(c,a);
        ll d;
        cin>>d;
        mp[{a,b,c}]=d;
        mp[{b,a,c}]=d;
    }
}

vector<ll> di(long long s,vector<vector<pair<long long,long long>>>& ab,map<tuple<ll,ll,ll>,ll>& mp,ll m){
    long long N=ab.size();
    priority_queue<pair<long long,long long>,vector<pair<long long,long long>>,greater<pair<long long,long long>>> pq;
    vector<long long> dist(N,(1ll<<60));
    dist[s]=0;
    pq.emplace(0,s);
    while(!pq.empty()){
        auto [cost,now]=pq.top();pq.pop();
        if(dist[now]<cost)continue;
        for(auto [tcost,to]:ab[now]){
            if(mp[{now,to,tcost}]<m)continue;
            if(chmin(dist[to],cost+tcost)){
                pq.emplace(dist[to],to);
            }
        }
    }
    return dist;
}

int main(){
    ll N,M,X;
    cin>>N>>M>>X;
    vector<vector<P>> ab(N);
    map<tuple<ll,ll,ll>,ll> mp;
    makeab(M,ab,mp);
    ll l=-1,r=1e10;
    while(r-l>1){
        ll m=(r+l)/2;
        vll d=di(0,ab,mp,m);
        if(d[N-1]<=X)l=m;
        else r=m;
    }
    cout << (l==0?-1:l) << endl;
}

0