답안 #349202

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
349202 2021-01-17T05:05:16 Z arnold518 Mousetrap (CEOI17_mousetrap) C++14
25 / 100
929 ms 77420 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e6;

int N, R, X;
vector<int> adj[MAXN+10];

int val[MAXN+10], dp[MAXN+10];

void dfs(int now, int bef, int p)
{
	val[now]=p;

	int a=0, b=0, cnt=0;
	for(int nxt : adj[now])
	{
		if(nxt==bef) continue;
		dfs(nxt, now, p+adj[nxt].size()-1);
		cnt++;
		if(a<=dp[nxt]) b=a, a=dp[nxt];
		else if(b<=dp[nxt]) b=dp[nxt];
	}
	dp[now]=b;
	if(cnt<=1) dp[now]=val[now];
	//printf("%d : %d %d\n", now, val[now], dp[now]);
}	

int main()
{
	scanf("%d%d%d", &N, &R, &X);
	for(int i=1; i<N; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	dfs(X, R, adj[X].size());
	printf("%d\n", dp[X]-1);
}

Compilation message

mousetrap.cpp: In function 'int main()':
mousetrap.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   35 |  scanf("%d%d%d", &N, &R, &X);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
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", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 23788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 418 ms 76524 KB Output is correct
2 Correct 354 ms 71020 KB Output is correct
3 Correct 929 ms 77292 KB Output is correct
4 Correct 422 ms 50412 KB Output is correct
5 Correct 869 ms 77292 KB Output is correct
6 Correct 916 ms 77420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 23788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 23788 KB Output isn't correct
2 Halted 0 ms 0 KB -