답안 #535469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535469 2022-03-10T10:36:19 Z Asymmetry Mousetrap (CEOI17_mousetrap) C++17
0 / 100
907 ms 77252 KB
//Autor: Bartłomiej Czarkowski
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';}
template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';}
#define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n'
#else
#define debug(...) {}
#endif

const int N = 1001000;
int n, a, b, m, q;
int par[N];
int dp[N]; // ile żeby uwięzić i wyprowadzić do ojca
vector<int> v[N];

void dfs_dp(int x) {
	vector<int> war = {-1, -2};
	for (int i : v[x]) {
		if (i == par[x]) {
			continue;
		}
		par[i] = x;
		dfs_dp(i);
		war.push_back(dp[i]);
	}
	nth_element(war.begin(), war.begin() + 1, war.end(), [&](int a, int b) {
		return a > b;
	});
	dp[x] = war[1] + 2;
}

int main() {
	scanf("%d%d%d", &n, &q, &m);
	for (int i = 1; i < n; ++i) {
		scanf("%d%d", &a, &b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dfs_dp(q);
	//~ for (int i = 1; i <= n; ++i) {
		//~ printf("%d: %d\n", i, dp[i]);
	//~ }
	printf("%d\n", dp[m]);
	return 0;
}

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, &q, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
mousetrap.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   scanf("%d%d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 380 ms 76208 KB Output is correct
2 Correct 398 ms 70932 KB Output is correct
3 Incorrect 907 ms 77252 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23744 KB Output isn't correct
2 Halted 0 ms 0 KB -