Submission #96328

# Submission time Handle Problem Language Result Execution time Memory
96328 2019-02-08T14:04:50 Z Bruteforceman Mousetrap (CEOI17_mousetrap) C++11
25 / 100
1062 ms 81400 KB
#include "bits/stdc++.h"
using namespace std;
vector <int> g[1000010];
int dp[1000010], cn[1000010];
int dep[1000010];
int m, t;

void dfs(int x, int par) {
	if(x == t) {
		cn[x] = 1;
		dp[x] = 0;
		dep[x] = 0;
		return ;
	}
	int deg = 0;
	int sib = 0;
	for(auto i : g[x]) {
		if(i - par) {
			dfs(i, x);
			cn[x] |= cn[i];
			++deg;
			if(cn[i]) {
				dep[x] = dep[i];
				sib = i;
			}
		}
	}
	dep[x] += deg - 1;
	vector <int> can;
	for(auto i : g[x]) {
		if(i - par) {
			if(cn[i]) {
				can.emplace_back(dp[i]);
			} else {
				if(cn[x]) {
					can.emplace_back(dp[i] + dep[x]);
				} else {
					can.emplace_back(dp[i] + deg);
				}
			}
		}
	}
	sort(can.begin(), can.end());
	reverse(can.begin(), can.end());
	if(cn[x]) {
		dp[x] = dp[sib];
	} else {
		dp[x] = 0;
	}
	if(can.size() > 1) {
		dp[x] = max(dp[x], can[1]);
	} else if (!cn[x] && can.size() == 1) {
		dp[x] = 1;		
	}
}

int main(int argc, char const *argv[])
{
	int n;
	scanf("%d %d %d", &n, &t, &m);
	for(int i = 1; i < n; i++) {
		int p, q;
		scanf("%d %d", &p, &q);
		g[p].emplace_back(q);
		g[q].emplace_back(p);
	}
	dfs(m, 0);
	printf("%d\n", dp[m]);
	return 0;
}

Compilation message

mousetrap.cpp: In function 'int main(int, const char**)':
mousetrap.cpp:60:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &t, &m);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mousetrap.cpp:63:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &p, &q);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 452 ms 78252 KB Output is correct
2 Correct 436 ms 72772 KB Output is correct
3 Correct 1040 ms 81372 KB Output is correct
4 Correct 592 ms 52600 KB Output is correct
5 Correct 1062 ms 81392 KB Output is correct
6 Correct 1051 ms 81400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -