Submission #28973

#TimeUsernameProblemLanguageResultExecution timeMemory
28973tlwpdusTriumphal arch (POI13_luk)C++11
100 / 100
1339 ms25192 KiB
#include <bits/stdc++.h>

using namespace std;

int n, t;
vector<int> lis[300100];
int d[300100];

void dfs(int here, int p) {
	int i, sum = 0;
	for (auto &there : lis[here]) {
		if (there==p) continue;
		dfs(there,here);
		sum += d[there];
	}
	d[here] = max(sum-t+1,1);
}

int main() {
	int i;

	scanf("%d",&n);
	for (i=0;i<n-1;i++) {
		int a, b;
		scanf("%d%d",&a,&b); --a; --b;
		lis[a].push_back(b); lis[b].push_back(a);
	}
	int s = 0, e = n;
	while(s<=e) {
		int m = (s+e)>>1;
		t = m;
		dfs(0,-1);
		if (d[0]>1) s = m+1;
		else e = m-1;
	}
	printf("%d\n",s);

    return 0;
}

Compilation message (stderr)

luk.cpp: In function 'void dfs(int, int)':
luk.cpp:10:6: warning: unused variable 'i' [-Wunused-variable]
  int i, sum = 0;
      ^
luk.cpp: In function 'int main()':
luk.cpp:22:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
luk.cpp:25:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&a,&b); --a; --b;
                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...