QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#878360#9696. Analysisucup-team3584#WA 1ms3712kbC++175.0kb2025-02-01 14:57:362025-02-01 14:57:42

Judging History

This is the latest submission verdict.

  • [2025-02-06 00:45:32]
  • hack成功,自动添加数据
  • (/hack/1517)
  • [2025-02-01 14:57:42]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3712kb
  • [2025-02-01 14:57:36]
  • Submitted

answer

#include <string.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> using vvvc = vector<vector<vector<T>>>;
template<class T> using pq = priority_queue<T,vector<T>,greater<T>>;
template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); }

int dx4[] = {1,0,-1,0};
int dy4[] = {0,1,0,-1};

#define overload5(a, b, c, d, e, name, ...) name
#define overload4(a, b, c, d, name, ...) name
#define REP0(n) for(ll jidlsjf = 0; jidlsjf < n; ++jidlsjf)
#define REP1(i, n) for(ll i = 0; i < (n); ++i)
#define REP2(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP3(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define per0(n) for(int jidlsjf = 0; jidlsjf < (n); ++jidlsjf)
#define per1(i, n) for(ll i = (n)-1; i >= 0; --i)
#define per2(i, a, b) for(ll i = (a)-1; i >= b; --i)
#define per3(i, a, b, c) for(ll i = (a)-1; i >= (b); i -= (c))
#define per(...) overload4(__VA_ARGS__, per3, per2, per1, per0)(__VA_ARGS__)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define drop(s) cout << #s << endl, exit(0)
#define si(c) (int)(c).size()
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define lbg(c, x) distance((c).begin(), lower_bound(all(c), (x), greater{}))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define ubg(c, x) distance((c).begin(), upper_bound(all(c), (x), greater{}))
#define rng(v, l, r) v.begin() + (l), v.begin() + (r)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define SORT(v) sort(all(v))
#define REV(v) reverse(all(v))
#define UNIQUE(x) SORT(x), x.erase(unique(all(x)), x.end())
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define overload2(_1, _2, name, ...) name
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))

ll inf = 1001001001001001001;

ll dp[500500][4];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,A,B;
    cin >> N >> A >> B;
    vvc<int>ki(N);
    rep(i,N-1) {
        int u,v;
        cin >> u >> v;
        u--;
        v--;
        ki[u].pb(v);
        ki[v].pb(u);
    }
    auto dfs = [&](auto &dfs,int n,int p) -> void {
        for(auto i:ki[n]) {
            if(i == p) continue;
            dfs(dfs,i,n);
            vc<ll>nxt(4,inf);
            rep(j,4) {
                rep(k,4) {
                    ll cost = dp[n][j]+dp[i][k];
                    if(j%2 == 0 && k <= 1) {
                        if(k == 0) cost += A;
                    }
                    if(j%2 == 0 && k > 1) {
                        cost += B;
                    }
                    if(j%2 == 1 && k <= 1) {
                        cost += B;
                    }
                    if(j%2 == 1 && k > 1) {
                        cost += B;
                    }
                    int id = j/2*2+k%2;
                    chmin(nxt[id],cost);
                }
            }
            rep(j,4) {
                rep(k,4) {
                    ll cost = dp[i][j]+dp[n][k];
                    if(j%2 == 0 && k <= 1) {
                        if(j == 0) {
                            cost += A;
                        }
                    }
                    if(j%2 == 0 && k > 1) {
                        cost += B;
                    }
                    if(j%2 == 1 && k <= 1) {
                        cost += B;
                    }
                    if(j%2 == 1 && k > 1) {
                        cost += B;
                        if(j == 3) {
                            cost += A;
                        }
                    }
                    int id = j/2*2+k%2;
                    chmin(nxt[id],cost);
                }
            }
            chmin(nxt[2],nxt[0]);
            chmin(nxt[3],nxt[0]);
            chmin(nxt[3],nxt[1]);
            rep(j,4) {
                dp[n][j] = nxt[j];
            }
        }
    };
    dfs(dfs,0,-1);
    cout << dp[0][3] << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3584kb

input:

5 100 1000
1 2
2 3
3 4
4 5

output:

0

result:

ok 1 number(s): "0"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

5 100 200
1 2
1 3
2 4
2 5

output:

100

result:

ok 1 number(s): "100"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3712kb

input:

10 133494816 109943166
10 8
5 3
1 2
8 9
8 5
2 4
8 7
8 6
10 1

output:

219886332

result:

ok 1 number(s): "219886332"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

10 165074331 854297934
6 2
2 7
9 8
2 9
9 10
6 3
6 4
5 6
6 1

output:

825371655

result:

ok 1 number(s): "825371655"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

9 719441223 227056392
4 6
9 2
5 3
1 4
6 8
1 9
1 7
3 1

output:

227056392

result:

ok 1 number(s): "227056392"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

10 216399993 137522662
9 6
1 2
2 9
4 1
10 3
7 5
5 4
3 7
2 8

output:

137522662

result:

ok 1 number(s): "137522662"

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 3712kb

input:

10 796722415 144928611
9 10
6 4
2 7
5 1
3 2
6 5
3 9
1 8
6 3

output:

144928611

result:

wrong answer 1st numbers differ - expected: '289857222', found: '144928611'