QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#363593#7936. Eliminate Treebobbilyking#WA 1ms3608kbC++201.5kb2024-03-24 00:40:552024-03-24 00:40:55

Judging History

你现在查看的是最新测评结果

  • [2024-03-24 00:40:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3608kb
  • [2024-03-24 00:40:55]
  • 提交

answer

#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include<bits/stdc++.h>
#include<math.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
#define FD(i, r, l) for(ll i = r; i > (l); --i)

#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = l; i < (r); ++i)

template<typename A, typename B>
A& chmax(A &a, B b) { return a < b ? (a=b): a; }

template<typename A, typename B>
A& chmin(A &a, B b) { return a > b ? (a=b): a; }




const ll N = 2e5 + 1;
vl adj[N];

pl dfs(ll i, ll p) {
    // 0 = me not free, 1 = me free 

    ll smfree = 0;
    ll bestExtra = 0;
    for (auto x: adj[i]) if (x-p) {
        auto [c0, c1] = dfs(x, i);
        smfree += max(c0, c1);
        chmax(bestExtra, c0 + 1 - max(c0, c1)); 
    }

    return {bestExtra + smfree, smfree};
}

int main(){
//    freopen("a.in", "r", stdin);
//    freopen("a.out", "w", stdout);

    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(20);
    
    G(n)
    F(i, 1, n) {
        G(x) G(y) adj[x].push_back(y); adj[y].push_back(x);
    }

    auto [x, y] = dfs(1, 1);

    // cout << "WTF " << x << ' ' << y << endl;
    ll mm = max(x, y);

    cout << mm + 2 * (n - 2 * mm) << '\n';
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3608kb

input:

5
1 2
2 3
3 4
3 5

output:

1

result:

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