結果
問題 | No.2677 Minmax Independent Set |
ユーザー | ei1333333 |
提出日時 | 2024-03-15 21:55:43 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 224 ms / 2,000 ms |
コード長 | 4,205 bytes |
コンパイル時間 | 4,780 ms |
コンパイル使用メモリ | 272,032 KB |
実行使用メモリ | 56,988 KB |
最終ジャッジ日時 | 2024-09-30 01:02:37 |
合計ジャッジ時間 | 12,251 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 2 ms
6,816 KB |
testcase_05 | AC | 159 ms
27,572 KB |
testcase_06 | AC | 164 ms
28,020 KB |
testcase_07 | AC | 165 ms
28,276 KB |
testcase_08 | AC | 164 ms
29,048 KB |
testcase_09 | AC | 169 ms
30,388 KB |
testcase_10 | AC | 127 ms
24,308 KB |
testcase_11 | AC | 131 ms
25,136 KB |
testcase_12 | AC | 224 ms
56,988 KB |
testcase_13 | AC | 207 ms
35,176 KB |
testcase_14 | AC | 181 ms
35,460 KB |
testcase_15 | AC | 218 ms
42,060 KB |
testcase_16 | AC | 200 ms
25,600 KB |
testcase_17 | AC | 209 ms
25,640 KB |
testcase_18 | AC | 112 ms
17,536 KB |
testcase_19 | AC | 137 ms
20,096 KB |
testcase_20 | AC | 34 ms
9,216 KB |
testcase_21 | AC | 154 ms
21,932 KB |
testcase_22 | AC | 9 ms
6,820 KB |
testcase_23 | AC | 3 ms
6,820 KB |
testcase_24 | AC | 2 ms
6,816 KB |
testcase_25 | AC | 2 ms
6,816 KB |
testcase_26 | AC | 2 ms
6,824 KB |
testcase_27 | AC | 3 ms
6,816 KB |
testcase_28 | AC | 114 ms
24,648 KB |
testcase_29 | AC | 197 ms
44,816 KB |
testcase_30 | AC | 2 ms
6,820 KB |
testcase_31 | AC | 2 ms
6,816 KB |
testcase_32 | AC | 2 ms
6,816 KB |
testcase_33 | AC | 2 ms
6,820 KB |
testcase_34 | AC | 2 ms
6,816 KB |
testcase_35 | AC | 2 ms
6,816 KB |
testcase_36 | AC | 2 ms
6,816 KB |
testcase_37 | AC | 2 ms
6,820 KB |
testcase_38 | AC | 3 ms
6,820 KB |
testcase_39 | AC | 3 ms
6,820 KB |
testcase_40 | AC | 3 ms
6,816 KB |
testcase_41 | AC | 4 ms
6,820 KB |
testcase_42 | AC | 8 ms
6,816 KB |
testcase_43 | AC | 15 ms
6,816 KB |
testcase_44 | AC | 32 ms
8,960 KB |
testcase_45 | AC | 78 ms
14,720 KB |
testcase_46 | AC | 204 ms
25,904 KB |
testcase_47 | AC | 205 ms
26,412 KB |
testcase_48 | AC | 210 ms
26,320 KB |
testcase_49 | AC | 206 ms
26,324 KB |
testcase_50 | AC | 41 ms
12,544 KB |
testcase_51 | AC | 4 ms
6,820 KB |
testcase_52 | AC | 97 ms
21,616 KB |
testcase_53 | AC | 84 ms
20,932 KB |
testcase_54 | AC | 4 ms
6,816 KB |
testcase_55 | AC | 133 ms
23,784 KB |
testcase_56 | AC | 144 ms
23,640 KB |
testcase_57 | AC | 139 ms
23,736 KB |
testcase_58 | AC | 129 ms
23,700 KB |
testcase_59 | AC | 135 ms
23,780 KB |
testcase_60 | AC | 89 ms
25,204 KB |
testcase_61 | AC | 95 ms
25,916 KB |
testcase_62 | AC | 95 ms
30,724 KB |
testcase_63 | AC | 109 ms
42,328 KB |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> using namespace std; using int64 = long long; const int64 infll = (1LL << 62) - 1; const int inf = (1 << 30) - 1; struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template< typename T1, typename T2 > ostream &operator<<(ostream &os, const pair< T1, T2 >& p) { os << p.first << " " << p.second; return os; } template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; } template< typename T > ostream &operator<<(ostream &os, const vector< T > &v) { for(int i = 0; i < (int) v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; } template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template< typename T = int64 > vector< T > make_v(size_t a) { return vector< T >(a); } template< typename T, typename... Ts > auto make_v(size_t a, Ts... ts) { return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...)); } template< typename T, typename V > typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) { t = v; } template< typename T, typename V > typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); } template< typename F > struct FixPoint : F { explicit FixPoint(F &&f) : F(forward< F >(f)) {} template< typename... Args > decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, forward< Args >(args)...); } }; template< typename F > inline decltype(auto) MFP(F &&f) { return FixPoint< F >{forward< F >(f)}; } #line 1 "graph/tree/rerooting.hpp" template< typename sum_t, typename key_t > struct ReRooting { struct Edge { int to; key_t data; sum_t dp, ndp; }; using F = function< sum_t(sum_t, sum_t) >; using G = function< sum_t(sum_t, key_t) >; vector< vector< Edge > > g; const F f; const G gg; const sum_t ident; vector< sum_t > subdp, dp; ReRooting(int V, const F f, const G g, const sum_t &ident) : g(V), f(f), gg(g), ident(ident), subdp(V, ident), dp(V, ident) {} void add_edge(int u, int v, const key_t &d) { g[u].emplace_back((Edge) {v, d, ident, ident}); g[v].emplace_back((Edge) {u, d, ident, ident}); } void add_edge_bi(int u, int v, const key_t &d, const key_t &e) { g[u].emplace_back((Edge) {v, d, ident, ident}); g[v].emplace_back((Edge) {u, e, ident, ident}); } void dfs_sub(int idx, int par) { for(auto &e : g[idx]) { if(e.to == par) continue; dfs_sub(e.to, idx); subdp[idx] = f(subdp[idx], gg(subdp[e.to], e.data)); } } void dfs_all(int idx, int par, const sum_t &top) { sum_t buff{ident}; for(int i = 0; i < (int) g[idx].size(); i++) { auto &e = g[idx][i]; e.ndp = buff; e.dp = gg(par == e.to ? top : subdp[e.to], e.data); buff = f(buff, e.dp); } dp[idx] = buff; buff = ident; for(int i = (int) g[idx].size() - 1; i >= 0; i--) { auto &e = g[idx][i]; if(e.to != par) dfs_all(e.to, idx, f(e.ndp, buff)); e.ndp = f(e.ndp, buff); buff = f(buff, e.dp); } } vector< sum_t > build() { dfs_sub(0, -1); dfs_all(0, -1, ident); return dp; } }; int main() { using pi = pair< int, int >; auto f = [](const pi& a, const pi& b) { return pi(a.first + b.first, a.second + b.second); }; auto g = [](const pi& a, bool x) { return pi(max(a.first, a.second + 1), a.first); }; int N; cin >> N; ReRooting< pi, bool > dp(N, f, g, pi()); for(int i = 1; i < N; i++) { int u, v; cin >> u >> v; --u, --v; dp.add_edge(u, v, false); } auto ans = dp.build(); int ret = inf; for(int i = 0; i < N; i++) { chmin(ret, ans[i].second + 1); } cout << ret << endl; }