QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#591124#7936. Eliminate Treeucup-team3519#WA 150ms25536kbC++171.3kb2024-09-26 14:19:432024-09-26 14:19:53

Judging History

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

  • [2024-09-26 14:19:53]
  • 评测
  • 测评结果:WA
  • 用时:150ms
  • 内存:25536kb
  • [2024-09-26 14:19:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define V vector
#define all1(x) (x).begin() + 1, (x).end()
#define fi first
#define se second
#define pb push_back
typedef pair<int, int> pi;

void solve() {
    int n; cin >> n;
    if(n == 1) {
        cout << 2 << endl;
        return;
    }
    V<V<int>> e(n + 1);
    V<int> f(n + 1);
    for(int i =1 ; i < n; i++) {
        int a, b; cin >> a >> b;
        e[a].pb(b);
        e[b].pb(a);
    }
    V<int> dep(n + 1);
    V<int> d(n + 1);
    auto dfs = [&](int x, int p, auto dfs) -> void {
        f[x] = p;
        d[p]++;
        dep[x] = dep[p] + 1;
        for(auto y : e[x]) {
            if(y == p) continue;
            dfs(y, x, dfs);
        }
    };
    dfs(1, 0, dfs);
    multiset<pi> st;
    for(int i = 1; i <= n; i++) {
        st.insert({dep[i], i});
    }
    int ans = 0;
    while(st.size()) {
        auto it = prev(st.end());
        int x = it->se;
        if(d[f[x]] == 1) {
            st.erase(it), st.erase({f[x], dep[f[x]]});
            ans++;
        } else {
            d[f[x]]--;
            st.erase(it);
            ans += 2;
        }
    }
    cout << ans << endl;

}
int main() {
    // int t; cin >> t;
    int t = 1;
    while(t--) solve();
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3488kb

input:

5
1 2
2 3
3 4
3 5

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

4
1 2
2 3
3 4

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 150ms
memory: 25536kb

input:

196666
32025 108673
181779 17115
162570 134230
93003 39673
89144 1269
185919 154408
34896 65369
35860 44720
55698 1390
45520 189805
147867 124511
135459 132555
87303 18031
176314 59695
33352 130640
87272 39716
35749 108807
143493 94486
126512 116598
40212 70895
132216 80855
22241 188737
150354 17346...

output:

269177

result:

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