QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#478421#7936. Eliminate Treeembusca#WA 54ms15052kbC++171.4kb2024-07-14 22:38:582024-07-14 22:38:58

Judging History

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

  • [2024-07-14 22:38:58]
  • 评测
  • 测评结果:WA
  • 用时:54ms
  • 内存:15052kb
  • [2024-07-14 22:38:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rp(i,a,b)        for(int i=a;i<b;i++)

const int N = 2e5+10;
vector<int> adj[N], vals;
vector<bool> used;
int resp = 0;

void dfs(int v, int p = -1){
    //cout << v << " " << resp << "!\n";
    for(auto ch : adj[v]) if(ch != p){
        dfs(ch, v);
    }
    for(auto ch : adj[v]) if(ch != p){
        if(vals[v] <= 2) break;
        if(vals[ch] == 1 && !used[ch]){
            used[ch] = true;
            vals[ch]--;
            vals[v]--;
            resp+=2;
        }
    }
    for(auto ch : adj[v]) if(ch != p){
        if(vals[ch] == 1 && !used[ch]){
            used[ch] = true;
            vals[v]--;
            used[v] = true;
            resp++;
        }
    }
    int temp = 0;
    for(auto ch : adj[v]) if(!used[ch]) temp++;
    vals[v] = temp;
    //cout << v << " " << resp << "?\n";
}

void solvetask(){
    int n;
    cin >> n;
    used.assign(n, false);
    vals.assign(n, 0);
    rp(i, 1, n){
        int u, v;
        cin >> u >> v;
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    rp(i, 0, n) vals[i] = adj[i].size();
    dfs(0);
    rp(i, 0, n) if(!used[i]) resp+=2;
    cout << resp << "\n";
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    ll t = 1;
    while(t--) solvetask();
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 8396kb

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: 8308kb

input:

4
1 2
2 3
3 4

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 54ms
memory: 15052kb

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:

191618

result:

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