QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#478461 | #7936. Eliminate Tree | embusca# | WA | 53ms | 14836kb | C++20 | 1.2kb | 2024-07-14 23:18:14 | 2024-07-14 23:18:14 |
Judging History
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);
if(vals[ch] == 0){
vals[v]--;
}
}
for(; vals[v] > 2; vals[v]--){
// cout << "DIMINUINDO V " << v << "\n";
resp += 2;
}
if(p == -1){
// cout << "ROOT \n";
resp += (vals[v] == 0 ? 2: 1);
}
else if(vals[v] == 2){
// cout << "CORTEI V " << v << '\n';
resp++;
vals[v] = 0;
}
//cout << v << " " << resp << "?\n";
}
void solvetask(){
int n;
cin >> n;
used.assign(n+1, false);
vals.assign(n+1, 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, 1, n+1) vals[i] = adj[i].size();
dfs(1);
cout << resp << "\n";
}
int main(){
cin.tie(0)->sync_with_stdio(0);
ll t = 1;
while(t--) solvetask();
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3648kb
input:
5 1 2 2 3 3 4 3 5
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
4 1 2 2 3 3 4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 53ms
memory: 14836kb
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:
138182
result:
ok 1 number(s): "138182"
Test #4:
score: -100
Wrong Answer
time: 50ms
memory: 14600kb
input:
192941 180913 51977 128686 137679 118562 93198 60438 181978 39944 140001 169718 122100 146644 138935 22544 124591 113645 112480 128660 133392 9985 102696 4089 62155 4760 3202 116481 17579 59343 141071 81968 156270 5544 186622 117322 35780 127098 110151 148427 70933 2244 44243 3778 176132 181512 1583...
output:
135476
result:
wrong answer 1st numbers differ - expected: '135478', found: '135476'