QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#392573 | #7936. Eliminate Tree | ucup-team3215# | WA | 245ms | 40144kb | C++20 | 1.2kb | 2024-04-17 17:24:36 | 2024-04-17 17:24:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using item = array<int, 2>;
vector< set<int> > g;
set<item> st;
void add(int u) {
st.insert({g[u].size(), u});
}
void rmleaf(int u) {
if (g[u].size()) {
int v = *g[u].begin();
st.erase({g[u].size(), u});
st.erase({g[v].size(), v});
g[u].erase(v);
g[v].erase(u);
add(v);
} else {
st.erase({g[u].size(), u});
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
g.resize(n);
for (int i = 0; i < n - 1; ++i) {
int u, v;
cin >> u >> v;
--u;--v;
g[u].insert(v);
g[v].insert(u);
}
for (int i = 0; i < n; ++i) {
add(i);
}
int ans = 0;
while (st.size()) {
auto [dx, x] = *st.begin();
if (g[x].size()) {
int y = *g[x].begin();
int dy = g[y].size();
if (dy <= 2) {
rmleaf(x);
rmleaf(y);
ans += 1;
continue;
}
}
rmleaf(x);
ans += 2;
}
cout << ans << endl;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
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: 3568kb
input:
4 1 2 2 3 3 4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 245ms
memory: 40144kb
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:
169523
result:
wrong answer 1st numbers differ - expected: '138182', found: '169523'