Submission #307303

# Submission time Handle Problem Language Result Execution time Memory
307303 2020-09-27T15:25:00 Z zoember Traffic (IOI10_traffic) C++11
0 / 100
17 ms 23808 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

const int MAXN = 1e6, MAXN2 = 2e9;
int total = 0, ans = MAXN2;
vector<int> adj[MAXN];

int dfs(int vertex, int parent, int p[]) {
	int cnt = 0, maxcon = 0;
	for(int next: adj[vertex]) {
		if(next != parent) {
			int curr = dfs(next, vertex, p);
			maxcon = max(maxcon, curr);
			cnt += curr;
		}
	}
	maxcon = max(maxcon, total-p[vertex]-maxcon);
	ans = min(ans, maxcon);
	cnt += p[vertex];
	return cnt;
}

int LocateCentre(int n, int p[], int s[], int d[]) {
	for(int i=0; i<(n-1); i++) {
		adj[s[i]].push_back(d[i]);
		adj[d[i]].push_back(s[i]);
	}
	for(int i=0; i<n; i++) {
		total += p[i];
	}
	dfs(0, -1, p);
	return ans;
}

//int main() {
////	freopen("hayfeast.in", "r", stdin);
////	freopen("hayfeast.out", "w", stdout);
//	ios_base::sync_with_stdio(false); 
//    cin.tie(NULL); cout.tie(NULL);
//    int n; 
//    cin >> n;
//    int p[n] = {0}, s[n] = {0}, d[n] = {0};
//    for(int i=0; i<n; i++) {
//    	cin >> p[i];
//	}
//	for(int i=0; i<(n-1); i++) {
//		cin >> s[i];
//	}
//	for(int i=0; i<(n-1); i++) {
//		cin >> d[i];
//	}
//	LocateCentre(n, p, s, d);
//}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Incorrect 17 ms 23808 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Incorrect 17 ms 23808 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Incorrect 17 ms 23808 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Incorrect 17 ms 23808 KB Output isn't correct
3 Halted 0 ms 0 KB -