QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#386953#7936. Eliminate Treecarbon111#WA 110ms31684kbC++14808b2024-04-11 21:57:292024-04-11 21:57:29

Judging History

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

  • [2024-04-11 21:57:29]
  • 评测
  • 测评结果:WA
  • 用时:110ms
  • 内存:31684kb
  • [2024-04-11 21:57:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
void solve()
{
	int n;
	cin>>n;
	vector<map<int,int>>g(n+1);
	vector<int>d(n+1);
	for(int i = 0;i<n-1;i++){
		int a,b;cin>>a>>b;
		g[a][b]++;
		g[b][a]++;
		d[a]++,d[b]++;
	} 
	int cnt = 0;
	function<bool(int,int)> dfs = [&](int u,int fa)->bool{
		bool ok = true;
		for(auto x:g[u]){
			int v = x.first;
			if(v==fa)continue;
			ok &= dfs(v,u);
		}
		
		if(ok==false){
			return true;
		}
		int t = d[fa] - (fa!=0);
		if((d[fa]==1||d[fa]==2)&&!(fa==1&&d[fa]==2)){
			cnt++;	
			d[u]--;
			return false;
		}
		d[fa]--;
		//cout<<fa<<" "<<d[fa]<<"d\n";
		cnt+=2;
		d[u]--;
		return true;
		
	};
	
	dfs(1,0);
	cout<<cnt<<"\n";
	
	
	
}
int main()
{
	cin.tie(0)->sync_with_stdio(0);
	int t = 1;
	while(t--)solve();
} 

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3616kb

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

input:

4
1 2
2 3
3 4

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 110ms
memory: 31684kb

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:

191621

result:

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