Submission #376147

# Submission time Handle Problem Language Result Execution time Memory
376147 2021-03-11T02:00:18 Z Kevin_Zhang_TW Designated Cities (JOI19_designated_cities) C++17
7 / 100
293 ms 25580 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l) == r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 200010;
const ll inf = 1ll << 59;

int n, q;
ll dprt[MAX_N], dpson[MAX_N], res[MAX_N];
int qv[MAX_N];
vector<pair<int,int>> edge[MAX_N];

ll dfs1(int x, int lst = -1) {
	for (auto [u, w] : edge[x]) if (u != lst) 
		dpson[x] += w + dfs1(u, x);
	return dpson[x];
}
void dfs2(int x, int lst = -1, ll upson = 0) {
	for (auto [u, w] : edge[x]) if (u == lst)
		upson += w;
	dprt[x] = upson + dpson[x];
	DE(x, dprt[x]);
	for (auto [u, w] : edge[x]) if (u != lst) {
		ll val = dprt[x] - w - dpson[u];
		dfs2(u, x, val);
	}
}

int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for (int a, b, c, d, i = 1;i < n;++i) {
		cin >> a >> b >> c >> d;
		edge[a].pb(b, c);
		edge[b].pb(a, d);
	}

	dfs1(1);
	dfs2(1);

	cin >> q;
	for (int i = 0;i < q;++i)
		cin >> qv[i];

	if (q > 1) return -1;

	for (int i = 0;i < q;++i) {
		res[i] = inf;
	   	if (qv[i] == 1)
			res[i] = *min_element(dprt+1, dprt+1+n);
		if (qv[i] == 2) {
			for (int x = 1;x <= n;++x)
				for (auto [u, w] : edge[x])
					chmin(res[i], res[u] + w);
		}
	}

	for (int i = 0;i < q;++i)
		cout << res[i] << '\n';

}

Compilation message

designated_cities.cpp: In function 'void dfs2(int, int, ll)':
designated_cities.cpp:14:17: warning: statement has no effect [-Wunused-value]
   14 | #define DE(...) 0
      |                 ^
designated_cities.cpp:34:2: note: in expansion of macro 'DE'
   34 |  DE(x, dprt[x]);
      |  ^~
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5100 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5100 KB Output is correct
2 Correct 263 ms 15940 KB Output is correct
3 Correct 293 ms 25068 KB Output is correct
4 Correct 238 ms 15980 KB Output is correct
5 Correct 233 ms 15972 KB Output is correct
6 Correct 242 ms 17516 KB Output is correct
7 Correct 221 ms 16228 KB Output is correct
8 Correct 289 ms 25580 KB Output is correct
9 Correct 152 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 5100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5100 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5100 KB Output is correct
2 Correct 263 ms 15940 KB Output is correct
3 Correct 293 ms 25068 KB Output is correct
4 Correct 238 ms 15980 KB Output is correct
5 Correct 233 ms 15972 KB Output is correct
6 Correct 242 ms 17516 KB Output is correct
7 Correct 221 ms 16228 KB Output is correct
8 Correct 289 ms 25580 KB Output is correct
9 Correct 152 ms 14940 KB Output is correct
10 Incorrect 4 ms 5100 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5100 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -