#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
/*
*/
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
#include "crocodile.h"
vector<pii> adj1[N], adj2[N];
vector<int> dp(N);
vector<bool> spl(N);
vector<bool> vis(N);
vector<int> topo;
void dfs1(int u){
vis[u] = 1;
for(auto [v,w] : adj2[u]){
if(vis[v]) conts;
dfs1(v);
}
topo.pb(u);
}
int travel_plan(int n, int m, int R[][2], int L[], int k, int P[])
{
rep(i,m){
int u = R[i][0], v = R[i][1], w = L[i];
adj1[u].pb({v,w}), adj1[v].pb({u,w});
}
rep(i,k){
spl[P[i]] = 1;
}
while(true){
bool changed = false;
rep(u,n){
if(spl[u]){
dp[u] = 0;
conts;
}
pii px = {inf1,inf1};
for(auto [v,w] : adj1[u]){
int x = dp[v]+w;
if(x < px.ff){
px.ss = px.ff;
px.ff = x;
}
else{
amin(px.ss,x);
}
}
int new_val = px.ss;
if(new_val != dp[u]){
changed = true;
}
dp[u] = new_val;
}
if(!changed) break;
}
int ans = dp[0];
return ans;
// priority_queue<pll,vector<pll>,greater<pll>> pq;
// vector<ll> dis(n+5,inf2);
// pq.push({0,0});
// while(!pq.empty()){
// auto [cost,u] = pq.top();
// pq.pop();
// if(vis[u]) conts;
// vis[u] = 1;
// dis[u] = cost;
// for(auto [v,w] : adj1[u]){
// pq.push({cost+w,v});
// }
// }
// rep1(u,n){
// for(auto [v,w] : adj1[u]){
// if(dis[u]+w == dis[v]){
// adj2[u].pb({v,w});
// }
// }
// }
// fill(all(vis),0);
// dfs1(0);
// trav(u,topo){
// if(spl[u]){
// dp[u] = 0;
// conts;
// }
// vector<int> vals;
// for(auto [v,w] : adj2[u]){
// vals.pb(dp[v]+w);
// }
// sort(all(vals));
// if(sz(vals) < 2){
// dp[u] = inf1;
// }
// else{
// dp[u] = vals[1];
// }
// }
// int ans = dp[0];
// return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9048 KB |
Output is correct |
2 |
Correct |
2 ms |
9052 KB |
Output is correct |
3 |
Correct |
2 ms |
9052 KB |
Output is correct |
4 |
Correct |
2 ms |
9052 KB |
Output is correct |
5 |
Correct |
2 ms |
9052 KB |
Output is correct |
6 |
Correct |
2 ms |
9052 KB |
Output is correct |
7 |
Correct |
2 ms |
9048 KB |
Output is correct |
8 |
Correct |
6 ms |
9052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9048 KB |
Output is correct |
2 |
Correct |
2 ms |
9052 KB |
Output is correct |
3 |
Correct |
2 ms |
9052 KB |
Output is correct |
4 |
Correct |
2 ms |
9052 KB |
Output is correct |
5 |
Correct |
2 ms |
9052 KB |
Output is correct |
6 |
Correct |
2 ms |
9052 KB |
Output is correct |
7 |
Correct |
2 ms |
9048 KB |
Output is correct |
8 |
Correct |
6 ms |
9052 KB |
Output is correct |
9 |
Correct |
3 ms |
9308 KB |
Output is correct |
10 |
Correct |
3 ms |
9052 KB |
Output is correct |
11 |
Correct |
3 ms |
9308 KB |
Output is correct |
12 |
Correct |
5 ms |
9308 KB |
Output is correct |
13 |
Correct |
6 ms |
9564 KB |
Output is correct |
14 |
Correct |
2 ms |
9052 KB |
Output is correct |
15 |
Correct |
3 ms |
9052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9048 KB |
Output is correct |
2 |
Correct |
2 ms |
9052 KB |
Output is correct |
3 |
Correct |
2 ms |
9052 KB |
Output is correct |
4 |
Correct |
2 ms |
9052 KB |
Output is correct |
5 |
Correct |
2 ms |
9052 KB |
Output is correct |
6 |
Correct |
2 ms |
9052 KB |
Output is correct |
7 |
Correct |
2 ms |
9048 KB |
Output is correct |
8 |
Correct |
6 ms |
9052 KB |
Output is correct |
9 |
Correct |
3 ms |
9308 KB |
Output is correct |
10 |
Correct |
3 ms |
9052 KB |
Output is correct |
11 |
Correct |
3 ms |
9308 KB |
Output is correct |
12 |
Correct |
5 ms |
9308 KB |
Output is correct |
13 |
Correct |
6 ms |
9564 KB |
Output is correct |
14 |
Correct |
2 ms |
9052 KB |
Output is correct |
15 |
Correct |
3 ms |
9052 KB |
Output is correct |
16 |
Correct |
452 ms |
46664 KB |
Output is correct |
17 |
Execution timed out |
2028 ms |
15956 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |