結果

問題 No.1898 Battle and Exchange
ユーザー 👑 emthrmemthrm
提出日時 2022-04-08 22:52:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 532 ms / 5,000 ms
コード長 3,200 bytes
コンパイル時間 2,920 ms
コンパイル使用メモリ 219,144 KB
実行使用メモリ 15,956 KB
最終ジャッジ日時 2023-08-19 01:23:43
合計ジャッジ時間 19,925 ms
ジャッジサーバーID
(参考情報)
judge9 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 19 ms
4,376 KB
testcase_18 AC 91 ms
5,596 KB
testcase_19 AC 142 ms
7,016 KB
testcase_20 AC 157 ms
7,400 KB
testcase_21 AC 443 ms
13,764 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 5 ms
4,380 KB
testcase_28 AC 7 ms
4,380 KB
testcase_29 AC 15 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 64 ms
6,996 KB
testcase_33 AC 119 ms
9,848 KB
testcase_34 AC 54 ms
6,140 KB
testcase_35 AC 89 ms
8,124 KB
testcase_36 AC 50 ms
7,620 KB
testcase_37 AC 41 ms
4,684 KB
testcase_38 AC 475 ms
15,956 KB
testcase_39 AC 350 ms
13,408 KB
testcase_40 AC 396 ms
14,740 KB
testcase_41 AC 317 ms
12,836 KB
testcase_42 AC 14 ms
4,376 KB
testcase_43 AC 275 ms
10,912 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 28 ms
4,380 KB
testcase_46 AC 129 ms
7,012 KB
testcase_47 AC 15 ms
4,376 KB
testcase_48 AC 37 ms
4,404 KB
testcase_49 AC 4 ms
4,376 KB
testcase_50 AC 4 ms
4,376 KB
testcase_51 AC 5 ms
4,376 KB
testcase_52 AC 7 ms
4,380 KB
testcase_53 AC 43 ms
4,692 KB
testcase_54 AC 32 ms
5,084 KB
testcase_55 AC 65 ms
4,900 KB
testcase_56 AC 60 ms
4,928 KB
testcase_57 AC 520 ms
14,856 KB
testcase_58 AC 517 ms
14,852 KB
testcase_59 AC 532 ms
14,824 KB
testcase_60 AC 495 ms
14,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

template <typename CostType>
struct Edge {
  int src, dst;
  CostType cost;
  explicit Edge(const int src, const int dst, const CostType cost = 0)
      : src(src), dst(dst), cost(cost) {}
  inline bool operator<(const Edge& x) const {
    if (cost != x.cost) return cost < x.cost;
    return src != x.src ? src < x.src : dst < x.dst;
  }
  inline bool operator<=(const Edge& x) const { return !(x < *this); }
  inline bool operator>(const Edge& x) const { return x < *this; }
  inline bool operator>=(const Edge& x) const { return !(*this < x); }
};

int main() {
  int n, m; cin >> n >> m;
  vector<vector<int>> graph(n);
  while (m--) {
    int u, v; cin >> u >> v; --u; --v;
    graph[u].emplace_back(v);
    graph[v].emplace_back(u);
  }
  vector<vector<int>> cards(n);
  vector<int> sum(n);
  int ub = 4;
  REP(i, n) {
    int a, b, c; cin >> a >> b >> c;
    cards[i] = {a, b, c};
    sort(ALL(cards[i]));
    sum[i] = a + b + c;
    chmax(ub, a + b + c + 1);
  }
  REP(i, n) sort(ALL(graph[i]), [&](int a, int b) -> bool { return sum[a] < sum[b]; });
  int lb = max({sum[0], sum[graph[0].front()] - cards[0].back() + 1, 3});
  // assert(lb < ub);
  while (ub - lb > 1) {
    const int mid = (lb + ub) / 2;
    vector<int> is_visited(n, -1), top3{mid - 2, 1, 1};
    auto merge = [&](int i) -> void {
      for (int e : cards[i]) top3.emplace_back(e);
      sort(ALL(top3), greater<int>());
      top3.resize(3);
    };
    is_visited[0] = is_visited[graph[0].front()] = 1;
    merge(0);
    merge(graph[0].front());
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
    FOR(i, 1, graph[0].size()) {
      const int e = graph[0][i];
      is_visited[e] = 0;
      que.emplace(sum[e], e);
    }
    for (int e : graph[graph[0].front()]) {
      if (e != 0) {
        is_visited[e] = 0;
        que.emplace(sum[e], e);
      }
    }
    while (!que.empty()) {
      const int i = que.top().second; que.pop();
      if (accumulate(ALL(top3), 0) <= sum[i]) break;
      is_visited[i] = 1;
      merge(i);
      for (int e : graph[i]) {
        if (is_visited[e] == -1) {
          is_visited[e] = 0;
          que.emplace(sum[e], e);
        }
      }
    }
    (is_visited[n - 1] == 1 ? ub : lb) = mid;
  }
  cout << "1 1 " << ub - 2 << '\n';
  return 0;
}
0