結果

問題 No.1154 シュークリームゲーム(Hard)
ユーザー fastmathfastmath
提出日時 2020-08-12 02:44:01
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,590 bytes
コンパイル時間 2,011 ms
コンパイル使用メモリ 165,776 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 18:21:25
合計ジャッジ時間 3,311 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 4 ms
5,376 KB
testcase_33 AC 4 ms
5,376 KB
testcase_34 AC 4 ms
5,376 KB
testcase_35 AC 4 ms
5,376 KB
testcase_36 AC 4 ms
5,376 KB
testcase_37 AC 3 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 4 ms
5,376 KB
testcase_41 AC 4 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

const int N = 1e3+7;
vector <int> g[N];
int n, a[N], cnt[N], par[N];
bool del[N];
void dfs(int u, int p) {
    par[u] = p;
    for (int v : g[u]) {
        if (v != p) {
            dfs(v, u);
        }   
    }   
}   

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].app(v); g[v].app(u);
    }       
    dfs(1, 1);
    const int INF = 1e18;
    for (int i = 1; i <= n; ++i)
        cnt[i] = 1;
    for (int t = 0; t < n - 1; ++t) {
        ii mx = mp(-INF, -INF);
        for (int u = 2; u <= n; ++u) {
            if (!del[u]) {
                mx = max(mx, mp(a[u], u));
            }   
        }   
        int u = mx.s;
        for (int i = 2; i <= n; ++i) {
            if (par[i] == u) {
                par[i] = par[u];
            }   
        }   
        del[u] = 1;
        if (cnt[par[u]]&1)
            a[par[u]] -= a[u];
        else            
            a[par[u]] += a[u];
        cnt[par[u]] += cnt[u];
    }   
    cout << a[1] << endl;
}
0