답안 #203078

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
203078 2020-02-19T08:58:45 Z dimash241 Designated Cities (JOI19_designated_cities) C++17
100 / 100
551 ms 54296 KB
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
using pt = pair<ll, ll>;
vector < pair<int, pt > > g[N];
int deg[N];
ll ans[N], sum;
ll d[N], up[N];
bool u[N];

void dfs(int v, int pr = 0) {
    for (auto e : g[v]) {
        if(e.F == pr) continue;
        d[e.F] = d[v] + e.S.F;
        up[e.F] = up[v] + e.S.S;
        sum += e.S.F;
        dfs(e.F, v);
    }
}

int main () {
   	SpeedForce;
	cin >> n;
	for (int i = 1; i < n; i ++) {
		int l, r, x, y;
		cin >> l >> r >> x >> y;
		g[l].pb({r, {x, y}});
		g[r].pb({l, {y, x}});
		deg[l]++, deg[r]++;
	}

	set < pt > q;
	for (int i = 1; i <= n; i ++) if (deg[i] == 1) {
		q.insert({g[i][0].S.S, i});
	}

	while(q.size() > 2) {
		int v = q.begin() -> S;
		ll cur = q.begin() -> F;
		u[v] = 1;

		q.erase(q.begin());

		int par;
		for (auto e : g[v]) if (!u[e.F]) {
			par = e.F;
			break;
		}

		deg[par]--;
		if (deg[par] == 1) {
			for (auto e : g[par]) if (!u[e.F]) {
			 	q.insert({cur + e.S.S, par});
				break;
			}

			continue;
		}

		ans[sz(q)] = ans[sz(q) + 1] + cur; 
	}
	ans[1] = INF;
	dfs(1, 0);

	for (int i = 1; i <= n; ++i) {
		ans[1] = min(ans[1], sum - d[i] + up[i]);
	}
	

	cin >> m;

	for (int i = 1; i <= m; i ++) {
		int x;
		cin >> x;
		cout << ans[x] << '\n';
	}

   	return Accepted;
}

// B...a

Compilation message

designated_cities.cpp: In function 'int main()':
designated_cities.cpp:94:7: warning: 'par' may be used uninitialized in this function [-Wmaybe-uninitialized]
   int par;
       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14456 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 14 ms 14328 KB Output is correct
4 Correct 14 ms 14456 KB Output is correct
5 Correct 14 ms 14456 KB Output is correct
6 Correct 14 ms 14456 KB Output is correct
7 Correct 14 ms 14456 KB Output is correct
8 Correct 15 ms 14456 KB Output is correct
9 Correct 14 ms 14432 KB Output is correct
10 Correct 14 ms 14456 KB Output is correct
11 Correct 14 ms 14456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 14456 KB Output is correct
2 Correct 476 ms 43764 KB Output is correct
3 Correct 316 ms 45624 KB Output is correct
4 Correct 419 ms 42360 KB Output is correct
5 Correct 480 ms 44328 KB Output is correct
6 Correct 471 ms 45176 KB Output is correct
7 Correct 455 ms 45860 KB Output is correct
8 Correct 316 ms 46840 KB Output is correct
9 Correct 391 ms 50200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14456 KB Output is correct
2 Correct 478 ms 43828 KB Output is correct
3 Correct 314 ms 46840 KB Output is correct
4 Correct 427 ms 42488 KB Output is correct
5 Correct 487 ms 44328 KB Output is correct
6 Correct 498 ms 45304 KB Output is correct
7 Correct 449 ms 48936 KB Output is correct
8 Correct 395 ms 47472 KB Output is correct
9 Correct 410 ms 50092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14456 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 14 ms 14328 KB Output is correct
4 Correct 14 ms 14456 KB Output is correct
5 Correct 14 ms 14456 KB Output is correct
6 Correct 14 ms 14456 KB Output is correct
7 Correct 14 ms 14456 KB Output is correct
8 Correct 15 ms 14456 KB Output is correct
9 Correct 14 ms 14432 KB Output is correct
10 Correct 14 ms 14456 KB Output is correct
11 Correct 14 ms 14456 KB Output is correct
12 Correct 13 ms 14456 KB Output is correct
13 Correct 17 ms 14840 KB Output is correct
14 Correct 19 ms 14840 KB Output is correct
15 Correct 16 ms 14968 KB Output is correct
16 Correct 17 ms 14712 KB Output is correct
17 Correct 18 ms 14712 KB Output is correct
18 Correct 16 ms 14840 KB Output is correct
19 Correct 18 ms 14728 KB Output is correct
20 Correct 17 ms 14840 KB Output is correct
21 Correct 16 ms 14840 KB Output is correct
22 Correct 17 ms 14716 KB Output is correct
23 Correct 17 ms 14840 KB Output is correct
24 Correct 16 ms 14840 KB Output is correct
25 Correct 17 ms 14840 KB Output is correct
26 Correct 16 ms 14840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 14456 KB Output is correct
2 Correct 476 ms 43764 KB Output is correct
3 Correct 316 ms 45624 KB Output is correct
4 Correct 419 ms 42360 KB Output is correct
5 Correct 480 ms 44328 KB Output is correct
6 Correct 471 ms 45176 KB Output is correct
7 Correct 455 ms 45860 KB Output is correct
8 Correct 316 ms 46840 KB Output is correct
9 Correct 391 ms 50200 KB Output is correct
10 Correct 13 ms 14456 KB Output is correct
11 Correct 478 ms 43828 KB Output is correct
12 Correct 314 ms 46840 KB Output is correct
13 Correct 427 ms 42488 KB Output is correct
14 Correct 487 ms 44328 KB Output is correct
15 Correct 498 ms 45304 KB Output is correct
16 Correct 449 ms 48936 KB Output is correct
17 Correct 395 ms 47472 KB Output is correct
18 Correct 410 ms 50092 KB Output is correct
19 Correct 14 ms 14456 KB Output is correct
20 Correct 489 ms 43768 KB Output is correct
21 Correct 331 ms 47096 KB Output is correct
22 Correct 486 ms 42488 KB Output is correct
23 Correct 523 ms 44060 KB Output is correct
24 Correct 462 ms 42996 KB Output is correct
25 Correct 471 ms 44152 KB Output is correct
26 Correct 488 ms 43000 KB Output is correct
27 Correct 470 ms 44332 KB Output is correct
28 Correct 447 ms 45048 KB Output is correct
29 Correct 453 ms 43512 KB Output is correct
30 Correct 451 ms 43944 KB Output is correct
31 Correct 462 ms 46880 KB Output is correct
32 Correct 373 ms 47748 KB Output is correct
33 Correct 378 ms 50200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14456 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 14 ms 14328 KB Output is correct
4 Correct 14 ms 14456 KB Output is correct
5 Correct 14 ms 14456 KB Output is correct
6 Correct 14 ms 14456 KB Output is correct
7 Correct 14 ms 14456 KB Output is correct
8 Correct 15 ms 14456 KB Output is correct
9 Correct 14 ms 14432 KB Output is correct
10 Correct 14 ms 14456 KB Output is correct
11 Correct 14 ms 14456 KB Output is correct
12 Correct 16 ms 14456 KB Output is correct
13 Correct 476 ms 43764 KB Output is correct
14 Correct 316 ms 45624 KB Output is correct
15 Correct 419 ms 42360 KB Output is correct
16 Correct 480 ms 44328 KB Output is correct
17 Correct 471 ms 45176 KB Output is correct
18 Correct 455 ms 45860 KB Output is correct
19 Correct 316 ms 46840 KB Output is correct
20 Correct 391 ms 50200 KB Output is correct
21 Correct 13 ms 14456 KB Output is correct
22 Correct 478 ms 43828 KB Output is correct
23 Correct 314 ms 46840 KB Output is correct
24 Correct 427 ms 42488 KB Output is correct
25 Correct 487 ms 44328 KB Output is correct
26 Correct 498 ms 45304 KB Output is correct
27 Correct 449 ms 48936 KB Output is correct
28 Correct 395 ms 47472 KB Output is correct
29 Correct 410 ms 50092 KB Output is correct
30 Correct 13 ms 14456 KB Output is correct
31 Correct 17 ms 14840 KB Output is correct
32 Correct 19 ms 14840 KB Output is correct
33 Correct 16 ms 14968 KB Output is correct
34 Correct 17 ms 14712 KB Output is correct
35 Correct 18 ms 14712 KB Output is correct
36 Correct 16 ms 14840 KB Output is correct
37 Correct 18 ms 14728 KB Output is correct
38 Correct 17 ms 14840 KB Output is correct
39 Correct 16 ms 14840 KB Output is correct
40 Correct 17 ms 14716 KB Output is correct
41 Correct 17 ms 14840 KB Output is correct
42 Correct 16 ms 14840 KB Output is correct
43 Correct 17 ms 14840 KB Output is correct
44 Correct 16 ms 14840 KB Output is correct
45 Correct 14 ms 14456 KB Output is correct
46 Correct 489 ms 43768 KB Output is correct
47 Correct 331 ms 47096 KB Output is correct
48 Correct 486 ms 42488 KB Output is correct
49 Correct 523 ms 44060 KB Output is correct
50 Correct 462 ms 42996 KB Output is correct
51 Correct 471 ms 44152 KB Output is correct
52 Correct 488 ms 43000 KB Output is correct
53 Correct 470 ms 44332 KB Output is correct
54 Correct 447 ms 45048 KB Output is correct
55 Correct 453 ms 43512 KB Output is correct
56 Correct 451 ms 43944 KB Output is correct
57 Correct 462 ms 46880 KB Output is correct
58 Correct 373 ms 47748 KB Output is correct
59 Correct 378 ms 50200 KB Output is correct
60 Correct 15 ms 14456 KB Output is correct
61 Correct 538 ms 46544 KB Output is correct
62 Correct 343 ms 47420 KB Output is correct
63 Correct 477 ms 45176 KB Output is correct
64 Correct 529 ms 46900 KB Output is correct
65 Correct 510 ms 45304 KB Output is correct
66 Correct 521 ms 46688 KB Output is correct
67 Correct 525 ms 45560 KB Output is correct
68 Correct 551 ms 47280 KB Output is correct
69 Correct 511 ms 47608 KB Output is correct
70 Correct 510 ms 45816 KB Output is correct
71 Correct 514 ms 46968 KB Output is correct
72 Correct 505 ms 49548 KB Output is correct
73 Correct 408 ms 49272 KB Output is correct
74 Correct 437 ms 54296 KB Output is correct