結果

問題 No.2387 Yokan Factory
ユーザー umezoumezo
提出日時 2023-07-22 01:44:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 564 ms / 5,000 ms
コード長 1,414 bytes
コンパイル時間 2,053 ms
コンパイル使用メモリ 213,932 KB
実行使用メモリ 14,076 KB
最終ジャッジ日時 2023-10-22 01:25:23
合計ジャッジ時間 8,236 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 1 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 1 ms
4,348 KB
testcase_09 AC 1 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
13,892 KB
testcase_16 AC 160 ms
12,836 KB
testcase_17 AC 370 ms
14,076 KB
testcase_18 AC 440 ms
12,492 KB
testcase_19 AC 355 ms
9,692 KB
testcase_20 AC 279 ms
8,460 KB
testcase_21 AC 564 ms
11,848 KB
testcase_22 AC 262 ms
8,300 KB
testcase_23 AC 403 ms
9,596 KB
testcase_24 AC 252 ms
9,012 KB
testcase_25 AC 247 ms
7,076 KB
testcase_26 AC 480 ms
10,444 KB
testcase_27 AC 554 ms
11,476 KB
testcase_28 AC 3 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 5 ms
4,348 KB
testcase_35 AC 4 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

const ll INF=1LL<<60;

struct Edge{
  int to;
  ll w;
  Edge(int to,ll w) : to(to),w(w) {}
};

using Graph=vector<vector<Edge>>;
using pli=pair<ll,int>;

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

vector<ll> dijkstra(Graph& G,int s){
  int n=G.size();
  vector<ll> dist(n,INF);
  dist[s]=0;
  
  priority_queue<pli,vector<pli>,greater<pli>> que;
  que.push({dist[s],s});
  
  while(!que.empty()){
    int v=que.top().second;
    ll d=que.top().first;
    que.pop();
    
    if(d>dist[v]) continue;
    
    for(auto e:G[v]){
      if(chmin(dist[e.to],dist[v]+e.w)){
        que.push({dist[e.to],e.to});
      }
    }
  }
  return dist;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  ll n,m,x;
  cin>>n>>m>>x;
  vector<ll> U(m),V(m),A(m),B(m);
  rep(i,m){
    cin>>U[i]>>V[i]>>A[i]>>B[i];
    U[i]--,V[i]--;
  }
  
  ll ok=0,ng=1e9+7;
  while(ng-ok>1){
    ll mid=(ok+ng)/2;
    Graph G(n);
    rep(i,m){
      if(B[i]<mid) continue;
      G[U[i]].push_back(Edge(V[i],A[i]));
      G[V[i]].push_back(Edge(U[i],A[i]));
    }
    vector<ll> dis=dijkstra(G,0);
    if(dis[n-1]>x) ng=mid;
    else ok=mid;
  }
  if(ok==0) cout<<-1<<endl;
  else cout<<ok<<endl;
  
  return 0;
}
0