Submission #103817

# Submission time Handle Problem Language Result Execution time Memory
103817 2019-04-02T19:28:43 Z luciocf Mousetrap (CEOI17_mousetrap) C++14
0 / 100
455 ms 64012 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e6+10;

typedef pair<int, int> pii;

int n, t, m;
int ans;

int atual;

int sz[maxn], pai[maxn];

vector<int> grafo[maxn];

int dfs(int u, int p)
{
	sz[u] = 1;

	for (auto v: grafo[u])
	{
		if (v == p) continue;

		pai[v] = u;
		sz[u] += dfs(v, u);
	}

	return sz[u];
}

void solve(int u, int p)
{
	for (int i = 0; i < (int)grafo[u].size()-1; i++)
	{
		int v = grafo[u][i];
		
		if (i%2 == 0)
		{
			ans++;
			continue;
		}
		
		solve(v, u);
	}

	ans++;
}

bool comp(int a, int b)
{
	if (a == pai[atual]) return 0;
	if (b == pai[atual]) return 1;
	if (atual == m && a == t) return 0;
	if (atual == m && b == t) return 1;

	return sz[a] > sz[b];
}

int main(void)
{
	scanf("%d %d %d", &n, &t, &m);

	for (int i = 1; i < n; i++)
	{
		int u, v;
		scanf("%d %d", &u, &v);

		grafo[u].push_back(v); grafo[v].push_back(u);
	}

	dfs(m, 0);

	for (int i = 1; i <= n; i++)
	{
		atual = i;
		sort(grafo[i].begin(), grafo[i].end(), comp);
	}

	solve(m, 0);

	printf("%d\n", ans);
}

Compilation message

mousetrap.cpp: In function 'int main()':
mousetrap.cpp:63: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:68:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 455 ms 64012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -