Submission #105279

# Submission time Handle Problem Language Result Execution time Memory
105279 2019-04-11T06:07:56 Z antimirage Designated Cities (JOI19_designated_cities) C++14
7 / 100
378 ms 38012 KB
#include <bits/stdc++.h>
 
#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
 
using namespace std;
 
const int N = 2e5 + 5;

int n, q, x, y, c, d;

long long ans, pref[N], res, ALL;

vector < vector < pair <int, pair <int, int> > > > g;
 
void dfs (int v, int p = 0, long long cur = 0)
{	
	for (auto to : g[v]){
		
		if (to.fr == p) continue;
		
		dfs(to.fr, v, cur + to.sc.fr - to.sc.sc);
		
		pref[v] = max( pref[v], pref[to.fr] + to.sc.fr - to.sc.sc );
		ans += to.sc.sc;
		
		ALL += to.sc.fr;
		ALL += to.sc.sc;
	}
	vector <long long> vec;
	
	for (auto to : g[v]){
		if (to.fr == p) continue;
		vec.pb( pref[to.fr] + to.sc.fr - to.sc.sc);
	}
	sort(all(vec));
	reverse(all(vec));
	
	if (vec.size() > 0)
		res = max(res, vec[0] + cur);
}
main(){
	
	cin >> n;
	g.resize(n + 1);
	
	for (int i = 1; i < n; i++){
		scanf("%d%d%d%d", &x, &y, &c, &d);
		g[x].pb( mk( y, mk(c, d) ) );	
		g[y].pb( mk( x, mk(d, c) ) );	
	}
	dfs(1);
	
	cin >> q;
	while (q--){
		cin >> x;
		//assert(x == 2);
		cout << ALL - res - ans << endl;
	}
}
/**
4
1 2 1 2
1 3 3 4
1 4 5 6
**/

Compilation message

designated_cities.cpp:45:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
designated_cities.cpp: In function 'int main()':
designated_cities.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d", &x, &y, &c, &d);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 327 ms 17732 KB Output is correct
3 Correct 366 ms 37240 KB Output is correct
4 Correct 297 ms 16348 KB Output is correct
5 Correct 322 ms 17028 KB Output is correct
6 Correct 312 ms 19236 KB Output is correct
7 Correct 303 ms 17904 KB Output is correct
8 Correct 378 ms 38012 KB Output is correct
9 Correct 276 ms 18720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 327 ms 17732 KB Output is correct
3 Correct 366 ms 37240 KB Output is correct
4 Correct 297 ms 16348 KB Output is correct
5 Correct 322 ms 17028 KB Output is correct
6 Correct 312 ms 19236 KB Output is correct
7 Correct 303 ms 17904 KB Output is correct
8 Correct 378 ms 38012 KB Output is correct
9 Correct 276 ms 18720 KB Output is correct
10 Incorrect 2 ms 384 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -