답안 #94527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
94527 2019-01-19T21:44:41 Z jasony123123 Mousetrap (CEOI17_mousetrap) C++11
25 / 100
1196 ms 56440 KB
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <array>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFOR(i,start,end) for(int i = start; i>end; i--)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define mt make_tuple
#define mp make_pair
#define v vector
#define sf scanf
#define pf printf
#define dvar(x) cout << #x << " := " << x << "\n"
#define darr(x,n) FOR(i,0,n) cout << #x << "[" << i << "]" << " := " << x[i] << "\n"

typedef long long ll;
typedef long double ld;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }

void io() {
#ifdef LOCAL_PROJECT 
	freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#else 
	/* online submission */

#endif 
	ios_base::sync_with_stdio(false); cin.tie(NULL);
}

const ll MOD = 1000000007LL;
const ll PRIME = 105943LL;
const ll INF = 1e12;
/****************************************************************/
const int MAXN = 1e6 + 1;
int N, T, M;
v<int> adj[MAXN];

bool findpath(v<int> &path, int cur, int goal, int par) {
	path.push_back(cur);
	if (cur == goal) return 1;
	for (auto c : adj[cur]) if (c != par) {
		if (findpath(path, c, goal, cur)) return 1;
		path.pop_back();
	}
	return 0;
}

pii bad;
ll moves(int x, int p) {
	v<ll> cdp = { 0,0 };
	int deg = 0;
	for (auto c : adj[x]) if (c != p && mp(c, x) != bad && mp(x, c) != bad) {
		cdp.push_back(moves(c, x));
		deg++;
	}
	sort(all(cdp), greater<ll>());
	return deg + cdp[1];
}

int main() {
	io();
	cin >> N >> T >> M;
	FOR(i, 0, N - 1) {
		int a, b; cin >> a >> b;
		adj[a].push_back(b), adj[b].push_back(a);
	}
	v<int> path;
	findpath(path, M, T, -1);
//	darr(path, path.size());

	ll ans = 0;
	FOR(i, 0, path.size() - 1) {
		bad = { (i-1<0?-1:path[i - 1]), path[i] };
		ans += moves(path[i], path[i + 1]);
	}
	cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 22 ms 23800 KB Output is correct
3 Correct 23 ms 23928 KB Output is correct
4 Correct 24 ms 23800 KB Output is correct
5 Incorrect 23 ms 23800 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 418 ms 55160 KB Output is correct
2 Correct 376 ms 52108 KB Output is correct
3 Correct 1196 ms 56244 KB Output is correct
4 Correct 516 ms 40184 KB Output is correct
5 Correct 1165 ms 56320 KB Output is correct
6 Correct 1162 ms 56440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 22 ms 23800 KB Output is correct
3 Correct 23 ms 23928 KB Output is correct
4 Correct 24 ms 23800 KB Output is correct
5 Incorrect 23 ms 23800 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 22 ms 23800 KB Output is correct
3 Correct 23 ms 23928 KB Output is correct
4 Correct 24 ms 23800 KB Output is correct
5 Incorrect 23 ms 23800 KB Output isn't correct
6 Halted 0 ms 0 KB -