結果

問題 No.2387 Yokan Factory
ユーザー planesplanes
提出日時 2023-07-21 21:45:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 647 ms / 5,000 ms
コード長 1,478 bytes
コンパイル時間 1,885 ms
コンパイル使用メモリ 179,604 KB
実行使用メモリ 13,484 KB
最終ジャッジ日時 2023-10-21 21:44:12
合計ジャッジ時間 7,911 ms
ジャッジサーバーID
(参考情報)
judge10 / 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 209 ms
12,940 KB
testcase_16 AC 130 ms
13,484 KB
testcase_17 AC 317 ms
12,164 KB
testcase_18 AC 458 ms
11,036 KB
testcase_19 AC 351 ms
8,768 KB
testcase_20 AC 260 ms
8,400 KB
testcase_21 AC 647 ms
10,656 KB
testcase_22 AC 240 ms
7,864 KB
testcase_23 AC 380 ms
8,792 KB
testcase_24 AC 126 ms
8,148 KB
testcase_25 AC 177 ms
6,544 KB
testcase_26 AC 464 ms
9,444 KB
testcase_27 AC 589 ms
10,156 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 4 ms
4,348 KB
testcase_30 AC 3 ms
4,348 KB
testcase_31 AC 4 ms
4,348 KB
testcase_32 AC 2 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 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

  #include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

ll INF=2e18;


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

ll N,M,X;cin>>N>>M>>X;

vector<vector<pair<ll,ll>>> vec(N,vector<pair<ll,ll>>(0));
vector<ll> a(M),b(M);

for(ll i=0;i<M;i++) {
  ll u,v;
  cin>>u>>v;
  cin>>a[i]>>b[i];
  u--;v--;
  vec[u].push_back(make_pair(v,i));
  vec[v].push_back(make_pair(u,i));
}


ll s=1;
ll g=1000000000;

while(s<g) {
  ll k=(s+g+1)/2;
vector<ll> d(N,INF);
d[0]=0;
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> S;
S.push(make_pair(0,0));

while(!S.empty()) {
  auto p=S.top();
  S.pop();

  if(d[p.second]<p.first) continue;

  for(auto x:vec[p.second]) {
    if(b[x.second]<k) continue;
    if(d[x.first]>p.first+a[x.second]) {
      d[x.first]=p.first+a[x.second];
      S.push(make_pair(d[x.first],x.first));
    }
  }
}



if(d[N-1]<=X) s=k;
else g=k-1;
}




vector<ll> d(N,INF);
d[0]=0;
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> S;
S.push(make_pair(0,0));

while(!S.empty()) {
  auto p=S.top();
  S.pop();

  if(d[p.second]<p.first) continue;

  for(auto x:vec[p.second]) {
    if(d[x.first]>p.first+a[x.second]) {
      d[x.first]=p.first+a[x.second];
      S.push(make_pair(d[x.first],x.first));
    }
  }
}

if(d[N-1]>X) {
  cout<<-1<<endl;
  return 0;
}




cout<<s<<endl;
}


0