結果

問題 No.1898 Battle and Exchange
ユーザー 👑 emthrmemthrm
提出日時 2022-04-08 22:44:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 3,190 bytes
コンパイル時間 2,269 ms
コンパイル使用メモリ 217,888 KB
実行使用メモリ 14,656 KB
最終ジャッジ日時 2023-08-19 01:13:33
合計ジャッジ時間 25,248 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
権限があれば一括ダウンロードができます

ソースコード

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(cards[i]), [&](int a, int b) -> bool { return sum[a] < sum[b]; });
  int lb = max({sum[0], sum[graph[0].front()] - cards[0].back(), 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()) {
      is_visited[graph[0][i]] = 0;
      que.emplace(sum[graph[0][i]], graph[0][i]);
    }
    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