結果

問題 No.2642 Don't cut line!
ユーザー KumaTachiRenKumaTachiRen
提出日時 2024-02-19 23:44:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,504 bytes
コンパイル時間 4,933 ms
コンパイル使用メモリ 275,460 KB
実行使用メモリ 74,340 KB
最終ジャッジ日時 2024-02-19 23:44:50
合計ジャッジ時間 12,241 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 191 ms
74,340 KB
testcase_01 AC 192 ms
74,340 KB
testcase_02 AC 192 ms
74,340 KB
testcase_03 AC 213 ms
74,340 KB
testcase_04 AC 191 ms
74,340 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 51 ms
6,676 KB
testcase_16 AC 160 ms
64,672 KB
testcase_17 AC 178 ms
69,968 KB
testcase_18 AC 131 ms
52,616 KB
testcase_19 AC 141 ms
53,576 KB
testcase_20 AC 42 ms
6,676 KB
testcase_21 AC 38 ms
6,676 KB
testcase_22 AC 201 ms
73,304 KB
testcase_23 AC 104 ms
40,880 KB
testcase_24 WA -
testcase_25 AC 137 ms
63,644 KB
testcase_26 AC 125 ms
48,980 KB
testcase_27 AC 189 ms
67,932 KB
testcase_28 WA -
testcase_29 AC 122 ms
49,612 KB
testcase_30 AC 154 ms
58,144 KB
testcase_31 AC 127 ms
52,380 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 1 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

struct Fast {
  Fast() {
    std::cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(10);
  }
} fast;

#define all(a) (a).begin(), (a).end()
#define contains(a, x) ((a).find(x) != (a).end())
#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--)
#define YN(b) cout << ((b) ? "YES" : "NO") << "\n";
#define Yn(b) cout << ((b) ? "Yes" : "No") << "\n";
#define yn(b) cout << ((b) ? "yes" : "no") << "\n";

template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  }
  return os;
}

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

using mint = modint998244353;
using vm = vector<mint>;
using vvm = vector<vm>;
inline ostream &operator<<(ostream &os, const mint x) { return os << x.val(); };

void solve() {
  int n, k;
  ll c;
  cin >> n >> k >> c;
  vi u(k), v(k), w(k), p(k), idx(k);
  rep(i, 0, k) {
    cin >> u[i] >> v[i] >> w[i] >> p[i];
    u[i]--;
    v[i]--;
    idx[i] = i;
  }
  sort(all(idx), [&w](auto const &lhs, auto const &rhs) { return w[lhs] < w[rhs]; });
  ll cost = 0;
  {
    dsu uf(n);
    for (auto i : idx)
      if (!uf.same(u[i], v[i])) {
        uf.merge(u[i], v[i]);
        cost += w[i];
      }
    if (uf.size(0) != n || cost > c) {
      cout << -1 << "\n";
      return;
    }
  }

  vi l(k, -1), r(k, k);
  vector<stack<int>> st(k);
  rep(loop, 0, 17) {
    rep(i, 0, k) {
      if (r[i] - l[i] > 1) {
        int x = l[i] + (r[i] - l[i]) / 2;
        st[x].push(i);
      }
    }
    dsu uf(n);
    rep(t, 0, k) {
      int x = idx[t];
      uf.merge(u[x], v[x]);
      while (!st[x].empty()) {
        int i = st[x].top();
        st[x].pop();
        if (uf.same(u[i], v[i]))
          r[i] = t;
        else
          l[i] = t;
      }
    }
  }
  int ans = 0;
  rep(i, 0, k) if (cost - w[idx[r[i]]] + w[i] <= c) chmax(ans, p[i]);
  cout << ans << "\n";
}

int main() {
  int t = 1;
  // cin >> t;
  while (t--) solve();
}
0