結果

問題 No.1898 Battle and Exchange
ユーザー SSRSSSRS
提出日時 2022-04-08 22:37:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 716 ms / 5,000 ms
コード長 1,548 bytes
コンパイル時間 2,380 ms
コンパイル使用メモリ 216,384 KB
実行使用メモリ 11,416 KB
最終ジャッジ日時 2024-05-06 08:11:19
合計ジャッジ時間 21,002 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 55 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 7 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 21 ms
5,376 KB
testcase_18 AC 101 ms
5,376 KB
testcase_19 AC 155 ms
5,632 KB
testcase_20 AC 157 ms
5,632 KB
testcase_21 AC 357 ms
9,344 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 5 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 22 ms
5,376 KB
testcase_28 AC 27 ms
5,376 KB
testcase_29 AC 93 ms
5,376 KB
testcase_30 AC 8 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 101 ms
5,504 KB
testcase_33 AC 192 ms
7,040 KB
testcase_34 AC 77 ms
5,376 KB
testcase_35 AC 129 ms
6,144 KB
testcase_36 AC 122 ms
5,888 KB
testcase_37 AC 43 ms
5,376 KB
testcase_38 AC 716 ms
11,416 KB
testcase_39 AC 418 ms
9,932 KB
testcase_40 AC 491 ms
10,824 KB
testcase_41 AC 363 ms
9,672 KB
testcase_42 AC 17 ms
5,376 KB
testcase_43 AC 336 ms
7,936 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 33 ms
5,376 KB
testcase_46 AC 133 ms
5,504 KB
testcase_47 AC 31 ms
5,376 KB
testcase_48 AC 65 ms
5,376 KB
testcase_49 AC 18 ms
5,376 KB
testcase_50 AC 17 ms
5,376 KB
testcase_51 AC 17 ms
5,376 KB
testcase_52 AC 37 ms
5,376 KB
testcase_53 AC 139 ms
5,376 KB
testcase_54 AC 270 ms
5,600 KB
testcase_55 AC 209 ms
5,392 KB
testcase_56 AC 286 ms
5,532 KB
testcase_57 AC 599 ms
9,856 KB
testcase_58 AC 517 ms
9,984 KB
testcase_59 AC 581 ms
9,984 KB
testcase_60 AC 502 ms
9,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int INF = 300000000;
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> E(N);
  for (int i = 0; i < M; i++){
    int U, V;
    cin >> U >> V;
    U--;
    V--;
    E[U].push_back(V);
    E[V].push_back(U);
  }
  vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; i++){
    cin >> A[i] >> B[i] >> C[i];
  }
  int mn = INF;
  for (int v : E[0]){
    mn = min(mn, A[v] + B[v] + C[v]);
  }
  int tv = 300000000, fv = 0;
  while (tv - fv > 1){
    int mid = (tv + fv) / 2;
    int a = mid, b = 1, c = 1;
    if (a + b + c <= A[0] + B[0] + C[0]){
      fv = mid;
    } else if (a + b + c - 1 + max({A[0], B[0], C[0]}) <= mn){
      fv = mid;
    } else {
      vector<bool> used(N, false);
      priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
      pq.push(make_pair(A[0] + B[0] + C[0], 0));
      while (!pq.empty()){
        int sum = pq.top().first;
        int v = pq.top().second;
        pq.pop();
        if (!used[v] && sum < a + b + c){
          used[v] = true;
          vector<int> tmp = {a, b, c, A[v], B[v], C[v]};
          sort(tmp.begin(), tmp.end(), greater<int>());
          a = tmp[0];
          b = tmp[1];
          c = tmp[2];
          for (int w : E[v]){
            if (!used[w]){
              pq.push(make_pair(A[w] + B[w] + C[w], w));
            }
          }
        }
      }
      if (used[N - 1]){
        tv = mid;
      } else {
        fv = mid;
      }
    }
  }
  cout << tv << ' ' << 1 << ' ' << 1 << endl;
}
0