#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
using ll = long long;
using ld = long double;
#define fi first
#define se second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
const int INF = 1e9;
const int MAXN = 1e5 + 7;
vector<pii> g[MAXN];
int vis[MAXN];
int f[MAXN];
vi p[MAXN];
int n, m;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
n = N;
m = M;
for(int i = 0; i < K; i++){
f[P[i]] = 1;
}
for(int i = 0; i < m; i++){
g[R[i][0]].pb({R[i][1], L[i]});
g[R[i][1]].pb({R[i][0], L[i]});
}
set<pii> s[3];
for(int i = 0; i < K; i++){
vis[P[i]] = 1;
p[P[i]].pb(0);
for(auto [u, c] : g[P[i]]){
p[u].pb(c);
}
}
for(int i = 0; i < n; i++){
if(f[i]){
continue;
}
sort(all(p[i]));
while(sz(p[i]) > 2){
p[i].pop_back();
}
s[sz(p[i])].insert({(sz(p[i]) == 0 ? 0 : p[i].back()), i});
}
while(sz(s[2])){
pii akt = *s[2].begin();
s[2].erase(s[2].begin());
int v = akt.se;
vis[v] = 1;
for(auto [u, c] : g[v]){
if(vis[u]){
continue;
}
if(sz(p[u]) == 0){
s[0].erase({0, u});
p[u].pb(akt.fi + c);
s[1].insert({akt.fi + c, u});
}else if(sz(p[u]) == 1){
s[1].erase({p[u].back(), u});
p[u].pb(akt.fi + c);
sort(all(p[u]));
s[2].insert({p[u].back(), u});
}else{
s[2].erase({p[u].back(), u});
p[u].pb(akt.fi + c);
sort(all(p[u]));
p[u].pop_back();
s[2].insert({p[u].back(), u});
}
}
}
return p[0][1];
}
/*int main(){
int R[7][2] = {{0, 2}, {0, 3}, {3, 2}, {2, 1}, {0, 1}, {0, 4}, {3, 4}};
int L[7] = {4, 3, 2, 10, 100, 7, 9};
int P[2] = {1, 3};
cout << travel_plan(5, 7, R, L, 2, P);
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
5212 KB |
Output is correct |
4 |
Correct |
3 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
5208 KB |
Output is correct |
6 |
Correct |
4 ms |
5208 KB |
Output is correct |
7 |
Correct |
3 ms |
5212 KB |
Output is correct |
8 |
Correct |
2 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
5212 KB |
Output is correct |
4 |
Correct |
3 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
5208 KB |
Output is correct |
6 |
Correct |
4 ms |
5208 KB |
Output is correct |
7 |
Correct |
3 ms |
5212 KB |
Output is correct |
8 |
Correct |
2 ms |
5212 KB |
Output is correct |
9 |
Correct |
3 ms |
5212 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
3 ms |
5184 KB |
Output is correct |
12 |
Correct |
5 ms |
5424 KB |
Output is correct |
13 |
Correct |
4 ms |
5464 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
3 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
5212 KB |
Output is correct |
4 |
Correct |
3 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
5208 KB |
Output is correct |
6 |
Correct |
4 ms |
5208 KB |
Output is correct |
7 |
Correct |
3 ms |
5212 KB |
Output is correct |
8 |
Correct |
2 ms |
5212 KB |
Output is correct |
9 |
Correct |
3 ms |
5212 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
3 ms |
5184 KB |
Output is correct |
12 |
Correct |
5 ms |
5424 KB |
Output is correct |
13 |
Correct |
4 ms |
5464 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
3 ms |
5212 KB |
Output is correct |
16 |
Correct |
670 ms |
58736 KB |
Output is correct |
17 |
Correct |
76 ms |
20564 KB |
Output is correct |
18 |
Correct |
146 ms |
21532 KB |
Output is correct |
19 |
Correct |
837 ms |
65236 KB |
Output is correct |
20 |
Correct |
277 ms |
52052 KB |
Output is correct |
21 |
Correct |
42 ms |
11348 KB |
Output is correct |
22 |
Correct |
350 ms |
49492 KB |
Output is correct |