답안 #463567

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
463567 2021-08-11T10:15:20 Z vanic Mousetrap (CEOI17_mousetrap) C++14
25 / 100
833 ms 73388 KB
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

const int maxn=1e6+5;

vector < int > ms[maxn];
int dp[maxn];

void dfs(int x, int prosl){
	dp[x]=ms[x].size()-1;
	int maksi=0, drugi=0;
	for(int i=0; i<(int)ms[x].size(); i++){
		if(ms[x][i]!=prosl){
			dfs(ms[x][i], x);
			if(dp[ms[x][i]]>maksi){
				drugi=maksi;
				maksi=dp[ms[x][i]];
			}
			else if(dp[ms[x][i]]>drugi){
				drugi=dp[ms[x][i]];
			}
		}
	}
	dp[x]+=drugi;
}

int main(){
	int n, t, m;
	scanf("%d%d%d", &n, &t, &m);
	t--;
	m--;
	int a, b;
	for(int i=0; i<n-1; i++){
		scanf("%d%d", &a, &b);
		a--;
		b--;
		ms[a].push_back(b);
		ms[b].push_back(a);
	}
	if(n==1){
		printf("0\n");
		return 0;
	}
	dfs(t, t);
	printf("%d\n", dp[m]);
	return 0;
}

Compilation message

mousetrap.cpp: In function 'int main()':
mousetrap.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |  scanf("%d%d%d", &n, &t, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
mousetrap.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |   scanf("%d%d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 390 ms 72320 KB Output is correct
2 Correct 355 ms 67332 KB Output is correct
3 Correct 833 ms 73388 KB Output is correct
4 Correct 396 ms 48348 KB Output is correct
5 Correct 809 ms 73264 KB Output is correct
6 Correct 802 ms 73264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23884 KB Output isn't correct
2 Halted 0 ms 0 KB -