#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
struct P{
int i; ll w;
P(){}
P(int _i, ll _w){i = _i, w = _w;}
};
struct compare{
bool operator () (P a, P b){return a.w > b.w;}
};
const int N = 1e5 + 69;
const ll INF = 1e18 + 69;
vector<P> graph[N];
void update(pair<ll, ll> &chode, ll x){
if (chode.first > x){
chode.second = chode.first;
chode.first = x;
}
else minimize(chode.second, x);
}
int travel_plan(int n, int m, int R[][2], int L[], int K, int E[]){
for(int i = 0; i<m; ++i){
int u = R[i][0], v = R[i][1];
ll w = L[i];
graph[u].push_back(P(v, w));
graph[v].push_back(P(u, w));
}
vector<ll> ans(n, INF);
for(int i = 0; i<K; ++i) {
int u = E[i];
ans[u] = 0;
}
set<pair<ll, int>> S;
vector<pair<ll, ll>> chode(n, {INF, INF});
for(int i = 0; i<n; ++i) if (ans[i] == INF) S.insert({INF, i});
else S.insert({0, i});
while(true) {
pair<ll, int> cur = *S.begin();
S.erase(cur);
ans[cur.second] = cur.first;
for(P v: graph[cur.second]){
S.erase({chode[v.i].second, v.i});
update(chode[v.i], cur.first + v.w);
S.insert({chode[v.i].second, v.i});
}
if (cur.second == 0) break;
}
return ans[0];
}
// int main(void){
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// int R[][2] = {{0,1}, {0,2}, {2,3}, {2,4}};
// int L[] = {2,3,1,4};
// int P[] = {1,3,4};
// cout << travel_plan(5, 4, R, L, 3, P) << "\n";
// return 0;
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Execution timed out |
2007 ms |
6744 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Execution timed out |
2007 ms |
6744 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Execution timed out |
2007 ms |
6744 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |