結果

問題 No.1898 Battle and Exchange
ユーザー SSRSSSRS
提出日時 2022-04-08 22:37:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 519 ms / 5,000 ms
コード長 1,548 bytes
コンパイル時間 2,144 ms
コンパイル使用メモリ 214,100 KB
実行使用メモリ 11,600 KB
最終ジャッジ日時 2023-08-19 01:03:44
合計ジャッジ時間 20,998 ms
ジャッジサーバーID
(参考情報)
judge9 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 51 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 17 ms
4,380 KB
testcase_18 AC 86 ms
4,620 KB
testcase_19 AC 134 ms
5,288 KB
testcase_20 AC 138 ms
5,380 KB
testcase_21 AC 287 ms
9,064 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 5 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 22 ms
4,380 KB
testcase_28 AC 25 ms
4,380 KB
testcase_29 AC 91 ms
4,380 KB
testcase_30 AC 8 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 85 ms
5,240 KB
testcase_33 AC 160 ms
6,796 KB
testcase_34 AC 66 ms
5,144 KB
testcase_35 AC 107 ms
6,012 KB
testcase_36 AC 102 ms
5,672 KB
testcase_37 AC 38 ms
4,380 KB
testcase_38 AC 519 ms
11,600 KB
testcase_39 AC 332 ms
9,832 KB
testcase_40 AC 377 ms
10,452 KB
testcase_41 AC 286 ms
9,320 KB
testcase_42 AC 15 ms
4,380 KB
testcase_43 AC 284 ms
7,816 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 29 ms
4,380 KB
testcase_46 AC 114 ms
5,356 KB
testcase_47 AC 28 ms
4,380 KB
testcase_48 AC 59 ms
4,376 KB
testcase_49 AC 17 ms
4,380 KB
testcase_50 AC 15 ms
4,376 KB
testcase_51 AC 15 ms
4,380 KB
testcase_52 AC 35 ms
4,380 KB
testcase_53 AC 132 ms
4,672 KB
testcase_54 AC 262 ms
5,100 KB
testcase_55 AC 199 ms
5,092 KB
testcase_56 AC 274 ms
5,288 KB
testcase_57 AC 427 ms
10,096 KB
testcase_58 AC 392 ms
9,644 KB
testcase_59 AC 444 ms
9,668 KB
testcase_60 AC 370 ms
9,588 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