結果

問題 No.2739 Time is money
ユーザー 👑 potato167potato167
提出日時 2024-04-20 20:49:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 224 ms / 2,000 ms
コード長 3,089 bytes
コンパイル時間 2,469 ms
コンパイル使用メモリ 209,084 KB
実行使用メモリ 20,568 KB
最終ジャッジ日時 2024-04-20 20:50:00
合計ジャッジ時間 6,487 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 70 ms
13,436 KB
testcase_03 AC 131 ms
17,440 KB
testcase_04 AC 65 ms
13,076 KB
testcase_05 AC 117 ms
13,056 KB
testcase_06 AC 124 ms
16,076 KB
testcase_07 AC 177 ms
19,968 KB
testcase_08 AC 185 ms
20,096 KB
testcase_09 AC 224 ms
20,352 KB
testcase_10 AC 149 ms
19,776 KB
testcase_11 AC 188 ms
20,264 KB
testcase_12 AC 141 ms
18,796 KB
testcase_13 AC 144 ms
18,944 KB
testcase_14 AC 132 ms
18,860 KB
testcase_15 AC 103 ms
17,800 KB
testcase_16 AC 106 ms
16,824 KB
testcase_17 AC 207 ms
20,544 KB
testcase_18 AC 195 ms
20,568 KB
testcase_19 AC 132 ms
17,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
const ll ILL=2167167167167167167;
const int INF=2100000000;
const int mod=998244353;
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a,bool upp=0){if(a) cout<<(upp?"YES\n":"Yes\n"); else cout<<(upp?"NO\n":"No\n");}
template<class T> void vec_out(vector<T> &p,int ty=0){
if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'<<p[i]<<'"';}cout<<"}\n";}
else{if(ty==1){cout<<p.size()<<"\n";}for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}}
template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T vec_sum(vector<T> &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;}
int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;}
template<class T> bool inside(T l,T x,T r){return l<=x&&x<r;}

using len_type=ll;
struct edge{
    int to;
    len_type length;
};

len_type dijkstra_movement(edge e,int from,len_type t){
    return t+e.length;
}


vector<len_type> dijkstra(vector<vector<edge>> &G,int start,len_type inf){
    int M=G.size();
    assert(M>start&&start>=0);
    vector<len_type> seen(M,inf);
    seen[start]=0;
    priority_queue<pair<len_type,int>,vector<pair<len_type,int>>,greater<pair<len_type,int>>> pq;
    pq.push({0,start});
    while(!pq.empty()){
        len_type time;
        int ver;
        tie(time,ver)=pq.top();
        pq.pop();
        if(seen[ver]<time) continue;
        for(edge x:G[ver]){
            len_type T=dijkstra_movement(x,ver,time);
            if(T<seen[x.to]){
                pq.push({T,x.to});
                seen[x.to]=T;
            }
        }
    }
    return seen;
}


void solve();
// oddloop
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t=1;
    //cin>>t;
    rep(i,0,t) solve();
}

void solve(){
    ll N,M,X;
    cin>>N>>M>>X;
    vector<vector<edge>> G(N);
    rep(i,0,M){
        int a,b;
        ll c,t;
        cin>>a>>b>>c>>t;
        a--,b--;
        G[a].push_back({b,c+X*t});
        G[b].push_back({a,c+X*t});
    }
    auto seen=dijkstra(G,0,ILL);
    if(seen[N-1]==ILL) cout<<"-1\n";
    else cout<<(X+seen[N-1]-1)/X<<endl;
}
0