QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#317740#7936. Eliminate Treeone_god_and_two_dogs#WA 1ms3488kbC++17674b2024-01-29 16:33:572024-01-29 16:33:57

Judging History

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

  • [2024-01-29 16:33:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3488kb
  • [2024-01-29 16:33:57]
  • 提交

answer

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

#define endl '\n'
using ll=long long ;


int main(){
	cin.tie(0)->sync_with_stdio(0);
	//freopen("hayasa","r",stdin);
	int n;
	cin>>n;
	vector<vector<int>>G(n);
	for(int i=1;i<n;++i){
		int a,b;
		cin>>a>>b;
		--a,--b;
		G[a].emplace_back(b);
		G[b].emplace_back(a);
	}
	auto dfs=[&](auto self,int x,int fa)->pair<int,int>{
		int s1=INT_MAX,s2=0,c=0;
		for(auto y:G[x]){
			if(y==fa)continue;
			auto [fi,se]=self(self,y,x);	
			++c;
			s2+=se;
			s1=min(fi-se,s1);
		}
		if(c==0)return {0,2};
		cout<<x<<" "<<fa<<" "<<s2<<" "<<s2+s1+1<<endl;
		return	{s2,min(s2+s1+1,s2+2)};
	};
	auto [r1,r2]=dfs(dfs,1,-1);
	cout<<r2<<endl;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3488kb

input:

5
1 2
2 3
3 4
3 5

output:

2 1 4 3
1 -1 5 4
4

result:

wrong answer 1st numbers differ - expected: '4', found: '2'