QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#363587 | #7936. Eliminate Tree | bobbilyking# | WA | 54ms | 15572kb | C++20 | 1.4kb | 2024-03-24 00:35:58 | 2024-03-24 00:35:59 |
Judging History
answer
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
#define FD(i, r, l) for(ll i = r; i > (l); --i)
#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = l; i < (r); ++i)
template<typename A, typename B>
A& chmax(A &a, B b) { return a < b ? (a=b): a; }
template<typename A, typename B>
A& chmin(A &a, B b) { return a > b ? (a=b): a; }
const ll N = 2e5 + 1;
vl adj[N];
pl dfs(ll i, ll p) {
pl cur{0, 0}; // 0 = me not free, 1 = me free
for (auto x: adj[i]) if (x-p) {
auto [c0, c1] = dfs(x, i);
chmax(cur.K, max(c0, c1));
chmax(cur.V, max(c0 + 1, c1));
}
return cur;
}
int main(){
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(20);
G(n)
F(i, 1, n) {
G(x) G(y) adj[x].push_back(y); adj[y].push_back(x);
}
auto [x, y] = dfs(1, 1);
ll mm = max(x, y);
cout << mm + 2 * (n - 2 * mm) << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3608kb
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: 3564kb
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: 15572kb
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:
390620
result:
wrong answer 1st numbers differ - expected: '138182', found: '390620'