QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#707959 | #7936. Eliminate Tree | bilbo_b# | WA | 105ms | 37072kb | C++17 | 1.6kb | 2024-11-03 18:24:59 | 2024-11-03 18:25:00 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;
signed main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n, a, b;
cin >> n;
vector<set<int> > g(n + 1);
vector<int> cnt(n + 1);
for (int i = 0; i < n - 1; ++i) {
cin >> a >> b;
g[a].insert(b);
g[b].insert(a);
// cnt[a] += 1;
// cnt[b] += 1;
}
set<pair<int, int> > t;
int left = n;
for (int i = 1; i <= n; ++i) {
if (g[i].size() == 1) {
int p = *g[i].begin();
t.insert({p, i});//???
left -= 1;
}
}
int ans = 0;
while(true) {
if(left == 0) {
if (t.size() == 1) {
ans += 2;
} else {
ans += 1;
}
break;
} else {
auto [_, v] = *t.begin();
t.erase(t.begin());
int p = *g[v].begin();
int cc = g[p].size();
if(cc == 2) {
ans += 1;
left -= 1;
g[p].erase(v);
int pp = *g[p].begin();
g[pp].erase(p);
if (g[pp].size() == 1) {
int ppp = *g[pp].begin();
left -= 1;
t.insert({ppp, pp});
}
} else {
ans += 2;
g[p].erase(v);
}
}
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
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: 3572kb
input:
4 1 2 2 3 3 4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 105ms
memory: 37072kb
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:
169355
result:
wrong answer 1st numbers differ - expected: '138182', found: '169355'