QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#55202#1957. Friendship GraphsKING_UT#WA 2ms5928kbC++20994b2022-10-12 18:28:442022-10-12 18:28:47

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-12 18:28:47]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5928kb
  • [2022-10-12 18:28:44]
  • 提交

answer

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

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define repn(i,b) rng(i,1,b+1)
#define pb push_back

template<class t>using vc=vector<t>;
using vi=vc<int>;

template<class t,class u>bool chmin(t&a,u b){
	if(a>b){
		a=b;
		return true;
	}else return false;
}

const int inf=INT_MAX/2-100;

int n,k,ans;
vc<int>edge[100005];
int dfs(int v,int u){
	priority_queue<int>que;
	for(auto to:edge[v]){
		if(to==u)continue;
		que.push(dfs(to,v)+1);
	}
	while(que.size() >= 2){
		int x = que.top();que.pop();
		int y = que.top();
		if(x+y > k) {
			ans++;
			continue;
		}
		else{
			que.push(x); break;
		}
	}
	if(que.empty()) return 0;
	else if(que.top() >= k){
		if(v != 1) ans++;
		return 0;
	}
	else return que.top();
}
void slv(){
	cin>>n>>k;
	k<<=1;
	rep(i,n-1){
		int u,v;cin>>u>>v;
		edge[v].pb(u);
		edge[u].pb(v);
	}
	dfs(1, -1);
	cout<<ans+1<<endl;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	slv();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 5928kb

input:

1000 499000
20 615
260 390
779 37
13 563
650 605
358 684
783 370
162 90
379 662
88 208
458 371
178 3
590 762
455 514
738 641
270 805
205 881
205 315
837 54
976 579
519 532
982 669
563 804
648 274
268 293
182 392
337 772
961 603
294 607
546 772
189 218
702 266
515 610
691 965
643 235
509 193
184 302
...

output:

1

result:

wrong answer 1st lines differ - expected: '0', found: '1'