結果
問題 | No.2642 Don't cut line! |
ユーザー | kwm_t |
提出日時 | 2024-02-25 16:22:55 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,978 bytes |
コンパイル時間 | 6,234 ms |
コンパイル使用メモリ | 324,196 KB |
実行使用メモリ | 51,740 KB |
最終ジャッジ日時 | 2024-09-29 10:57:17 |
合計ジャッジ時間 | 11,174 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 226 ms
51,108 KB |
testcase_02 | AC | 218 ms
51,740 KB |
testcase_03 | AC | 216 ms
47,992 KB |
testcase_04 | AC | 218 ms
47,764 KB |
testcase_05 | AC | 225 ms
49,292 KB |
testcase_06 | AC | 42 ms
6,820 KB |
testcase_07 | AC | 42 ms
6,820 KB |
testcase_08 | AC | 42 ms
6,820 KB |
testcase_09 | AC | 42 ms
6,820 KB |
testcase_10 | AC | 41 ms
6,816 KB |
testcase_11 | AC | 42 ms
6,816 KB |
testcase_12 | AC | 43 ms
6,816 KB |
testcase_13 | AC | 41 ms
6,820 KB |
testcase_14 | AC | 41 ms
6,816 KB |
testcase_15 | AC | 43 ms
6,816 KB |
testcase_16 | AC | 91 ms
17,672 KB |
testcase_17 | AC | 171 ms
43,296 KB |
testcase_18 | AC | 197 ms
44,264 KB |
testcase_19 | AC | 145 ms
35,804 KB |
testcase_20 | AC | 65 ms
16,128 KB |
testcase_21 | AC | 43 ms
6,816 KB |
testcase_22 | AC | 65 ms
13,928 KB |
testcase_23 | AC | 217 ms
48,564 KB |
testcase_24 | AC | 96 ms
21,504 KB |
testcase_25 | AC | 79 ms
19,456 KB |
testcase_26 | AC | 51 ms
9,728 KB |
testcase_27 | AC | 135 ms
33,004 KB |
testcase_28 | AC | 201 ms
45,020 KB |
testcase_29 | AC | 57 ms
12,672 KB |
testcase_30 | AC | 69 ms
17,664 KB |
testcase_31 | AC | 162 ms
38,816 KB |
testcase_32 | AC | 66 ms
15,232 KB |
testcase_33 | AC | 2 ms
6,816 KB |
testcase_34 | AC | 2 ms
6,816 KB |
testcase_35 | AC | 2 ms
6,816 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; //using mint = modint998244353; //const int mod = 998244353; //using mint = modint1000000007; //const int mod = 1000000007; //const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define P pair<int,int> template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } #include <vector> using S = long long; S op(S a, S b) { return max(a, b); } S e() { return 0; } struct HeavyLightDecomposition { HeavyLightDecomposition(std::vector<std::vector<int>> &_g, std::vector<S>&_val) :g(_g), val(_val) { n = g.size(); sz.resize(n); par.resize(n); in.resize(n); out.resize(n); rev.resize(n); head.resize(n); deep.resize(n); } int n; std::vector<std::vector<int>>g; std::vector<int>sz, par, in, out, rev, head, deep; std::vector<S>val; segtree<S, op, e>seg; void build() { dfs_sz(0); int time = 0; dfs_hld(0, time); initSegmentTree(); } void dfs_sz(int v, int d = 0, int p = -1) { deep[v] = d; par[v] = p; sz[v] = 1; if (g[v].size() && (p == g[v][0]))std::swap(g[v][0], g[v].back()); for (auto &e : g[v]) { if (p == e)continue; dfs_sz(e, d + 1, v); sz[v] += sz[e]; if (sz[g[v][0]] < sz[e])std::swap(g[v][0], e); } } void dfs_hld(int v, int &time, int p = -1) { in[v] = time; time++; rev[in[v]] = v; for (auto &e : g[v]) { if (p == e)continue; if (e == g[v][0])head[e] = head[v]; else head[e] = e; dfs_hld(e, time, v); } out[v] = time; } void initSegmentTree() { std::vector<S>_val(n); for (int i = 0; i < n; ++i)_val[i] = val[rev[i]]; seg = segtree<S, op, e>(_val); } S query(int u, int v) { S ret = e(); for (;; v = par[head[v]]) { if (in[u] > in[v])std::swap(u, v); if (head[u] == head[v])break; auto get = seg.prod(in[head[v]], in[v] + 1); ret = op(ret, get); } auto get = seg.prod(in[u], in[v] + 1); ret = op(ret, get); return ret; } int la(int v, int k) { while (1) { int u = head[v]; if (in[v] - k >= in[u])return rev[in[v] - k]; k -= in[v] - in[u] + 1; v = par[u]; } } int lca(int u, int v) { for (;; v = par[head[v]]) { if (in[u] > in[v])std::swap(u, v); if (head[u] == head[v])return u; } } int dist(int u, int v) { return deep[u] + deep[v] - 2 * deep[lca(u, v)]; } // point update void update_point(int u, S x) { auto get = seg.get(in[u]); seg.set(in[u], get + 1); } void debug() { for (int i = 0; i < n; ++i) std::cout << seg.prod(i, i + 1) << " "; std::cout << std::endl; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; long long c; cin >> c; struct Edge { int u, v, w, p; bool operator<(const Edge& other)const { return w < other.w; } }; vector<Edge>e(m); rep(i, m) { cin >> e[i].u >> e[i].v >> e[i].w >> e[i].p; e[i].u--; e[i].v--; } sort(all(e)); vector<vector<int>>to(2 * n - 1); dsu uf(n); int ans = 0; long long mncost = 0; vector<S>v(n * 2 - 1); int idx = n; for (auto &e : e) { if (uf.same(e.u, e.v))continue; to[e.u].emplace_back(idx); to[idx].emplace_back(e.u); to[idx].emplace_back(e.v); to[e.v].emplace_back(idx); chmax(ans, e.p); mncost += e.w; uf.merge(e.u, e.v); v[idx] = e.w; idx++; } if (mncost > c) { cout << -1 << endl; return 0; } HeavyLightDecomposition hld(to, v); hld.build(); for (auto &e : e) { if (e.p <= ans) continue; auto get = hld.query(e.u, e.v); if (mncost - get + e.w < c)ans = e.p; } cout << ans << endl; return 0; }