# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
459617 | 2021-08-08T20:44:06 Z | nickmet2004 | Aesthetic (NOI20_aesthetic) | C++11 | 779 ms | 83724 KB |
#include<bits/stdc++.h> #define ll long long using namespace std; const int N = 3e5 + 5; ll n , m , au[N] , av[N] , aw[N]; ll u , v , w , A = 0; vector<pair<ll, pair<ll , ll> > > adj[N]; ll d1[N] , dn[N] , f[N] , par[N] , path[N] , son[N]; priority_queue<pair<ll , ll> > pq; multiset<pair<ll , ll>> S; vector<ll> B[N] , T[N]; void q(int x){ f[x] = 1; for(auto y : adj[x]){ //cout << "h"; auto it = S.find({dn[y.first] + y.second.first + d1[x] , y.second.second}); if(f[y.first]) S.erase(it); else S.insert({dn[x] + y.second.first + d1[y.first] , y.second.second}); } } void dfs(int u , int p){ if(path[u]) son[u] = u; else son[u] = son[p]; T[son[u]].emplace_back(u); for(int v : B[u]) dfs(v , u); } main (){ ios_base::sync_with_stdio(0); //cin.tie(0); scanf("%d%d" , &n , &m); for(int i =0; i <m; ++i) scanf("%d%d%d" , &au[i] , &av[i], &aw[i]); for(int i = m - 1; ~i; --i){ u = au[i] , v = av[i] , w= aw[i]; adj[u].push_back({v , {w , A}}); adj[v].push_back({u , {w , A}}); A = max(A , w); //cout << "j"; } for(int i = 1; i <= n; ++i) d1[i] = dn[i] = 1e18; d1[1] = 0; dn[n] = 0; pq.push({0 , 1}); while(pq.size()){ auto T = pq.top(); pq.pop(); u = T.second , w = -T.first; if(f[u])continue; f[u] = 1; for(auto e : adj[u]){ v = e.first; if(!f[v] && d1[v] > w + e.second.first){ par[v] = u; d1[v] = w + e.second.first; pq.push({-d1[v] , v}); } } //cout << "k"; } for(int i = 1; i <= n; ++i)f[i] = 0; //memset(f , 0 ,sizeof(f)); pq.push({0, n}); while(pq.size()){ auto T = pq.top(); pq.pop(); u = T.second , w = -T.first; if(f[u])continue; f[u] = 1; for(auto e : adj[u]){ v = e.first; if(!f[v] && dn[v] > w + e.second.first){ dn[v]= w + e.second.first; pq.push({-dn[v] , v}); } } //cout << "l"; } ll X = n; while(1){ path[X] = 1; if(X == 1) break; X = par[X]; //cout << "n"; } for(int i = 1; i <= n; ++i)B[par[i]].emplace_back(i); dfs(1 , 0); for(int i = 1; i <= n; ++i) f[i] =0; u = n; ll ans = d1[n]; //cout << "ka"; ll k; while(1){ //cout << "ha"; if(u == 1)break; for(ll v : T[u]) q(v); //if(!S.size())continue; k = S.begin()->first + S.begin()->second; auto i = S.begin(); ++i; if(i != S.end()) k =min(k , i->first); ans = max(ans , k); u = par[u]; } //cout << ans; printf("%d" ,ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 21464 KB | Output is correct |
2 | Correct | 12 ms | 21452 KB | Output is correct |
3 | Incorrect | 12 ms | 21452 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 21464 KB | Output is correct |
2 | Correct | 12 ms | 21452 KB | Output is correct |
3 | Incorrect | 12 ms | 21452 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 753 ms | 70236 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 715 ms | 71744 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 561 ms | 64996 KB | Output is correct |
2 | Correct | 291 ms | 68800 KB | Output is correct |
3 | Correct | 277 ms | 59832 KB | Output is correct |
4 | Correct | 250 ms | 58804 KB | Output is correct |
5 | Correct | 261 ms | 58464 KB | Output is correct |
6 | Correct | 274 ms | 59676 KB | Output is correct |
7 | Correct | 269 ms | 58076 KB | Output is correct |
8 | Correct | 252 ms | 58544 KB | Output is correct |
9 | Correct | 244 ms | 57508 KB | Output is correct |
10 | Correct | 282 ms | 60616 KB | Output is correct |
11 | Correct | 253 ms | 58196 KB | Output is correct |
12 | Correct | 622 ms | 65676 KB | Output is correct |
13 | Correct | 252 ms | 58488 KB | Output is correct |
14 | Correct | 239 ms | 80872 KB | Output is correct |
15 | Correct | 177 ms | 70852 KB | Output is correct |
16 | Correct | 498 ms | 64716 KB | Output is correct |
17 | Correct | 594 ms | 64720 KB | Output is correct |
18 | Correct | 483 ms | 63028 KB | Output is correct |
19 | Correct | 315 ms | 69120 KB | Output is correct |
20 | Correct | 315 ms | 69016 KB | Output is correct |
21 | Correct | 297 ms | 69060 KB | Output is correct |
22 | Correct | 300 ms | 69072 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 561 ms | 64996 KB | Output is correct |
2 | Correct | 291 ms | 68800 KB | Output is correct |
3 | Correct | 277 ms | 59832 KB | Output is correct |
4 | Correct | 250 ms | 58804 KB | Output is correct |
5 | Correct | 261 ms | 58464 KB | Output is correct |
6 | Correct | 274 ms | 59676 KB | Output is correct |
7 | Correct | 269 ms | 58076 KB | Output is correct |
8 | Correct | 252 ms | 58544 KB | Output is correct |
9 | Correct | 244 ms | 57508 KB | Output is correct |
10 | Correct | 282 ms | 60616 KB | Output is correct |
11 | Correct | 253 ms | 58196 KB | Output is correct |
12 | Correct | 622 ms | 65676 KB | Output is correct |
13 | Correct | 252 ms | 58488 KB | Output is correct |
14 | Correct | 239 ms | 80872 KB | Output is correct |
15 | Correct | 177 ms | 70852 KB | Output is correct |
16 | Correct | 498 ms | 64716 KB | Output is correct |
17 | Correct | 594 ms | 64720 KB | Output is correct |
18 | Correct | 483 ms | 63028 KB | Output is correct |
19 | Correct | 315 ms | 69120 KB | Output is correct |
20 | Correct | 315 ms | 69016 KB | Output is correct |
21 | Correct | 297 ms | 69060 KB | Output is correct |
22 | Correct | 300 ms | 69072 KB | Output is correct |
23 | Correct | 745 ms | 66132 KB | Output is correct |
24 | Correct | 353 ms | 69180 KB | Output is correct |
25 | Correct | 381 ms | 59000 KB | Output is correct |
26 | Correct | 372 ms | 58628 KB | Output is correct |
27 | Correct | 363 ms | 58372 KB | Output is correct |
28 | Correct | 419 ms | 59924 KB | Output is correct |
29 | Correct | 427 ms | 58844 KB | Output is correct |
30 | Correct | 391 ms | 59200 KB | Output is correct |
31 | Correct | 417 ms | 59880 KB | Output is correct |
32 | Correct | 391 ms | 57812 KB | Output is correct |
33 | Correct | 416 ms | 59424 KB | Output is correct |
34 | Correct | 746 ms | 65936 KB | Output is correct |
35 | Correct | 388 ms | 58412 KB | Output is correct |
36 | Correct | 274 ms | 83724 KB | Output is correct |
37 | Correct | 305 ms | 83692 KB | Output is correct |
38 | Correct | 667 ms | 65576 KB | Output is correct |
39 | Correct | 697 ms | 65220 KB | Output is correct |
40 | Correct | 779 ms | 66204 KB | Output is correct |
41 | Correct | 371 ms | 69196 KB | Output is correct |
42 | Correct | 352 ms | 69108 KB | Output is correct |
43 | Correct | 383 ms | 69140 KB | Output is correct |
44 | Correct | 399 ms | 69072 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 21464 KB | Output is correct |
2 | Correct | 12 ms | 21452 KB | Output is correct |
3 | Incorrect | 12 ms | 21452 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |