Submission #463571

# Submission time Handle Problem Language Result Execution time Memory
463571 2021-08-11T10:22:35 Z vanic Mousetrap (CEOI17_mousetrap) C++14
25 / 100
1039 ms 65008 KB
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

const int maxn=1e6+5;

vector < int > ms[maxn];
int gore[maxn];
bool bio[maxn];
int dp[maxn];

void dfs(int x, int prosl){
	int br=0;
	for(int i=0; i<(int)ms[x].size(); i++){
		if(bio[ms[x][i]]){
			br++;
		}
	}
	dp[x]=ms[x].size()-1-br;
	int maksi=0, drugi=0;
	for(int i=0; i<(int)ms[x].size(); i++){
		if(ms[x][i]!=prosl && !bio[ms[x][i]]){
			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]];
			}
		}
	}
	bio[x]=1;
	dp[x]+=drugi;
}

void rokaj(int x, int prosl){
	gore[x]=prosl;
	for(int i=0; i<(int)ms[x].size(); i++){
		if(ms[x][i]!=prosl){
			rokaj(ms[x][i], x);
		}
	}
}

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;
	}
	rokaj(t, t);
	int sol=0;
	int x=m;
	while(gore[x]!=x){
		dfs(x, gore[x]);
		sol+=dp[x];
		x=gore[x];
	}
	printf("%d\n", sol);
	return 0;
}

Compilation message

mousetrap.cpp: In function 'int main()':
mousetrap.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |  scanf("%d%d%d", &n, &t, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
mousetrap.cpp:57:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   scanf("%d%d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23772 KB Output is correct
2 Correct 14 ms 23780 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 13 ms 23692 KB Output is correct
5 Incorrect 13 ms 23716 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 399 ms 63888 KB Output is correct
2 Correct 354 ms 59808 KB Output is correct
3 Correct 987 ms 64972 KB Output is correct
4 Correct 474 ms 44388 KB Output is correct
5 Correct 1024 ms 65008 KB Output is correct
6 Correct 1039 ms 64968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23772 KB Output is correct
2 Correct 14 ms 23780 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 13 ms 23692 KB Output is correct
5 Incorrect 13 ms 23716 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23772 KB Output is correct
2 Correct 14 ms 23780 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 13 ms 23692 KB Output is correct
5 Incorrect 13 ms 23716 KB Output isn't correct
6 Halted 0 ms 0 KB -