Submission #285028

# Submission time Handle Problem Language Result Execution time Memory
285028 2020-08-28T09:07:38 Z admin Aesthetic (NOI20_aesthetic) C++17
35 / 100
1351 ms 40312 KB
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
 
vector<tuple<int, int, int> > adj[300001];
int pre[300001], preve[300001], par[300001], depth[300001];
ll dis[2][300001];
void dijkstra(int s, int t) {
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > pq;
	dis[t][s] = 0;
	pq.push({0, s});
	ll c; int u;
	while (!pq.empty()) {
		tie(c, u) = pq.top();
		pq.pop();
		if (dis[t][u] != c) continue;
		for (int i=0; i<adj[u].size(); i++) {
			int v, w, b;
			tie(v, w, b) = adj[u][i];
			if (dis[t][v] != -1 && dis[t][v] <= c + w) continue;
			if (t == 0) {
				pre[v] = u;
				preve[v] = b;
				depth[v] = depth[u] + 1;
			}
			dis[t][v] = c + w;
			pq.push({dis[t][v], v});
		}
	}
}
int findp(int u) {
	return u == par[u] ? u : par[u] = findp(par[u]);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	bool isline[300001];
	int n, m, u, v, w, b, warr[300001], inc[300001];
	cin >> n >> m;
	for (int i=1; i<=m; i++) {
		cin >> u >> v >> w;
		adj[u].emplace_back(v, w, i);
		adj[v].emplace_back(u, w, i);
		warr[i] = w;
      assert(u != v);
	}
	inc[m] = 0;
	for (int i=m-1; i; i--) inc[i] = max(inc[i+1], warr[i+1]);
	for (int i=0; i<2; i++) fill(dis[i]+1, dis[i]+n+1, -1);
	dijkstra(1, 0);
	dijkstra(n, 1);
	
	ll lo = dis[0][n] + 1, hi = dis[0][n] + 1e9, ans = dis[0][n], cut;
	bool valid;
	fill(isline+1, isline+m+1, false);
	for (int i=n; i; i=pre[i]) {
		par[i] = i;
		isline[preve[i]] = true;
	}
	while (lo <= hi) {
		cut = (lo + hi) / 2;
		for (int i=1; i<=n; i++) par[i] = pre[i];
		for (int i=n; i; i=pre[i]) par[i] = i;
		for (int i=1; i<=n; i++) {
			for (auto tup : adj[i]) {
				tie(v, w, b) = tup;
				u = i;
				if (min(dis[0][u]+dis[1][v], dis[0][v]+dis[1][u]) + w >= cut) continue;
				if (isline[b]) continue;
				u = findp(u), v = findp(v);
				if (depth[u] > depth[v]) swap(u, v);
				while (v != u) {
					par[v] = pre[v];
					v = findp(v);
				}
			}
		}
		v = findp(n);
		valid = false;
		while (v > 1) {
			u = pre[v], b = preve[v], w = warr[preve[v]];
			if (min(dis[0][u]+dis[1][v], dis[0][v]+dis[1][u]) + w + inc[b] >= cut) valid = true;
			v = findp(pre[v]);
		}
		if (valid) {
			ans = cut;
			lo = cut + 1;
		}
		else hi = cut - 1;
	}
	cout << ans;
}

Compilation message

Aesthetic.cpp: In function 'void dijkstra(int, int)':
Aesthetic.cpp:17:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |   for (int i=0; i<adj[u].size(); i++) {
      |                 ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 7 ms 7680 KB Output is correct
10 Correct 7 ms 7680 KB Output is correct
11 Correct 7 ms 7552 KB Output is correct
12 Correct 7 ms 7552 KB Output is correct
13 Correct 7 ms 7552 KB Output is correct
14 Correct 7 ms 7552 KB Output is correct
15 Correct 7 ms 7552 KB Output is correct
16 Correct 6 ms 7552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1343 ms 31836 KB Output is correct
2 Correct 1276 ms 32120 KB Output is correct
3 Correct 1281 ms 31992 KB Output is correct
4 Correct 1321 ms 31864 KB Output is correct
5 Correct 1351 ms 31864 KB Output is correct
6 Correct 1305 ms 32504 KB Output is correct
7 Correct 1317 ms 32340 KB Output is correct
8 Correct 1303 ms 32504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1330 ms 32192 KB Output is correct
2 Correct 1318 ms 32016 KB Output is correct
3 Correct 1336 ms 32140 KB Output is correct
4 Correct 1318 ms 32528 KB Output is correct
5 Correct 1302 ms 31988 KB Output is correct
6 Correct 1287 ms 32040 KB Output is correct
7 Correct 1273 ms 32152 KB Output is correct
8 Correct 1299 ms 32376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 211 ms 40312 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 211 ms 40312 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 7 ms 7680 KB Output is correct
10 Correct 7 ms 7680 KB Output is correct
11 Correct 7 ms 7552 KB Output is correct
12 Correct 7 ms 7552 KB Output is correct
13 Correct 7 ms 7552 KB Output is correct
14 Correct 7 ms 7552 KB Output is correct
15 Correct 7 ms 7552 KB Output is correct
16 Correct 6 ms 7552 KB Output is correct
17 Correct 1343 ms 31836 KB Output is correct
18 Correct 1276 ms 32120 KB Output is correct
19 Correct 1281 ms 31992 KB Output is correct
20 Correct 1321 ms 31864 KB Output is correct
21 Correct 1351 ms 31864 KB Output is correct
22 Correct 1305 ms 32504 KB Output is correct
23 Correct 1317 ms 32340 KB Output is correct
24 Correct 1303 ms 32504 KB Output is correct
25 Correct 1330 ms 32192 KB Output is correct
26 Correct 1318 ms 32016 KB Output is correct
27 Correct 1336 ms 32140 KB Output is correct
28 Correct 1318 ms 32528 KB Output is correct
29 Correct 1302 ms 31988 KB Output is correct
30 Correct 1287 ms 32040 KB Output is correct
31 Correct 1273 ms 32152 KB Output is correct
32 Correct 1299 ms 32376 KB Output is correct
33 Runtime error 211 ms 40312 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -