結果
問題 | No.2642 Don't cut line! |
ユーザー | kwm_t |
提出日時 | 2024-02-25 16:25:35 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 228 ms / 4,000 ms |
コード長 | 3,979 bytes |
コンパイル時間 | 5,983 ms |
コンパイル使用メモリ | 324,524 KB |
実行使用メモリ | 51,636 KB |
最終ジャッジ日時 | 2024-09-29 10:57:28 |
合計ジャッジ時間 | 10,968 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 223 ms
51,024 KB |
testcase_02 | AC | 228 ms
51,636 KB |
testcase_03 | AC | 222 ms
48,000 KB |
testcase_04 | AC | 218 ms
47,700 KB |
testcase_05 | AC | 222 ms
49,268 KB |
testcase_06 | AC | 41 ms
6,816 KB |
testcase_07 | AC | 42 ms
6,816 KB |
testcase_08 | AC | 42 ms
6,816 KB |
testcase_09 | AC | 43 ms
6,816 KB |
testcase_10 | AC | 42 ms
6,816 KB |
testcase_11 | AC | 42 ms
6,820 KB |
testcase_12 | AC | 43 ms
6,816 KB |
testcase_13 | AC | 41 ms
6,816 KB |
testcase_14 | AC | 40 ms
6,816 KB |
testcase_15 | AC | 43 ms
6,816 KB |
testcase_16 | AC | 89 ms
17,704 KB |
testcase_17 | AC | 177 ms
43,408 KB |
testcase_18 | AC | 197 ms
44,408 KB |
testcase_19 | AC | 138 ms
35,588 KB |
testcase_20 | AC | 65 ms
16,000 KB |
testcase_21 | AC | 44 ms
6,820 KB |
testcase_22 | AC | 65 ms
13,952 KB |
testcase_23 | AC | 224 ms
48,432 KB |
testcase_24 | AC | 88 ms
21,632 KB |
testcase_25 | AC | 75 ms
19,456 KB |
testcase_26 | AC | 51 ms
9,728 KB |
testcase_27 | AC | 139 ms
32,896 KB |
testcase_28 | AC | 205 ms
45,044 KB |
testcase_29 | AC | 59 ms
12,544 KB |
testcase_30 | AC | 73 ms
17,536 KB |
testcase_31 | AC | 168 ms
38,708 KB |
testcase_32 | AC | 65 ms
15,360 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; }