답안 #355504

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
355504 2021-01-22T14:52:10 Z deadeye Traffic (IOI10_traffic) C++14
0 / 100
15 ms 23916 KB
#include "traffic.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define si second
typedef pair<int,int> pi;

#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 69
#endif
template <typename Arg>
void __f(string name, Arg arg) {
	cerr << name << " = " << arg << endl;
}
template <typename Head, typename... Tail>
void __f(string names, Head head, Tail... tail) {
	string cur = "";
	for (auto ch: names){if(ch==','){break;}else{cur+=ch;}}
	string nxt = names.substr(cur.size()+2);
	cerr << cur << " = " << head << ", ";
	__f(nxt, tail...);
}

const int MXN = 1000005, INF = 2e9 + 10;
int sz[MXN], ans[MXN], ret = INF, total, num[MXN];
vector<int> adj[MXN];

void dfs(int x, int p) {
	for (auto i: adj[x]) if (i != p) {
		dfs(i, x);
		num[x] += num[i] + sz[i];
		ans[x] = max(ans[x], num[x]);
	}
	ans[x] = max(ans[x], total - num[x] - sz[x]);
}

int LocateCentre(int N, int P[], int S[], int D[]) {
	for (int i = 0; i < N; ++i) {
		total += P[i];
		sz[i] = P[i];
	}
	for (int i = 0; i < N - 1; ++i) {
		adj[S[i]].pb(D[i]);
		adj[D[i]].pb(S[i]);
	}
	dfs(0, 0);
	for (int i = 0; i < N; ++i) {
		ret = min(ret, ans[i]);
	}
	return ret;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Incorrect 15 ms 23916 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Incorrect 15 ms 23916 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Incorrect 15 ms 23916 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Incorrect 15 ms 23916 KB Output isn't correct
3 Halted 0 ms 0 KB -