QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#357600#7936. Eliminate TreeWhimsical#WA 54ms14084kbC++23730b2024-03-19 01:38:402024-03-19 01:38:41

Judging History

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

  • [2024-03-19 01:38:41]
  • 评测
  • 测评结果:WA
  • 用时:54ms
  • 内存:14084kb
  • [2024-03-19 01:38:40]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	ll n;cin>>n;
	vector<vi> adj(n);
	rep(i,0,n-1){
		int u,v;cin>>u>>v;u--;v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	ll c[2]={};
	function<void(int,int,int)> dfs = [&](int u, int p, int co){
		c[co]++;
		for(int v:adj[u]){
			if(v==p)continue;
			dfs(v,u,co^1);
		}
	};
	dfs(0,-1,0);
	ll d=abs(c[1]-c[0]);
	cout<<(d+(n+d)/2)<<"\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3812kb

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

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

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:

98351

result:

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