#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]) if (ans[v.i] == INF){
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;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6744 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6744 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
3 ms |
7000 KB |
Output is correct |
10 |
Correct |
1 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
6 ms |
7260 KB |
Output is correct |
13 |
Correct |
3 ms |
7256 KB |
Output is correct |
14 |
Correct |
1 ms |
6748 KB |
Output is correct |
15 |
Correct |
2 ms |
6748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6744 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
3 ms |
7000 KB |
Output is correct |
10 |
Correct |
1 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
6 ms |
7260 KB |
Output is correct |
13 |
Correct |
3 ms |
7256 KB |
Output is correct |
14 |
Correct |
1 ms |
6748 KB |
Output is correct |
15 |
Correct |
2 ms |
6748 KB |
Output is correct |
16 |
Correct |
747 ms |
69724 KB |
Output is correct |
17 |
Correct |
102 ms |
26316 KB |
Output is correct |
18 |
Correct |
109 ms |
30032 KB |
Output is correct |
19 |
Correct |
812 ms |
91736 KB |
Output is correct |
20 |
Correct |
236 ms |
72588 KB |
Output is correct |
21 |
Correct |
50 ms |
14852 KB |
Output is correct |
22 |
Correct |
390 ms |
67892 KB |
Output is correct |