#include "crocodile.h"
#include <bits/stdc++.h>
#define MAX 100001
#define INF INT_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second
#define gett(x,m) get<m>(x)
#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define sorta(a,sz) sort(a,a+sz)
#define inputar(a,b){\
for(int i=0;i<b;i++){\
cin >> a[i];\
}\
}
#define inputvec(a,b){\
for(int i=0;i<b;i++){\
ll num;\
cin >> num;\
a.pb(num);\
}\
}
#define outputar(a,b){\
for(int i=0;i<b;i++){\
cout << a[i] << " ";\
}\
cout << "\n";\
}
#define outputvec(a){\
for(auto x:a){\
cout << x << " ";\
}\
cout << "\n";\
}
#define reset(a,n,v){\
for(int i=0;i<n;i++){\
a[i]=v;\
}\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
inline void USACO(string filename){
freopen((filename+".in").c_str(),"r",stdin);
freopen((filename+".out").c_str(),"w",stdout);
}
vector<vector<pii>> g;
int dist[MAX];
int a1[MAX],b1[MAX];
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
g.resize(N);
for(int i=0;i<N;i++){
dist[i]=INF;
}
for(int i=0;i<M;i++){
g[R[i][0]].pb(mp(R[i][1],L[i]));
g[R[i][1]].pb(mp(R[i][0],L[i]));
}
for(int i=0;i<K;i++){
dist[P[i]]=0;
}
set<tll> a;
for(int i=0;i<N;i++){
if(dist[i]==0){
continue;
}
ll h=INF,h1=INF;
for(auto x:g[i]){
if(dist[x.ff]==0){
if(x.ss<h){
h1=min(h1,h);
h=x.ss;
}
else if(x.ss<h1){
h1=x.ss;
}
}
}
a1[i]=h;
b1[i]=h1;
a.ins(mt(h,h1,i));
}
for(int i=0;i<N-K;i++){
auto it=a.begin();
tll t=*it;
a.erase(t);
//cout << gett(t,0) << " " << gett(t,1) << " " << gett(t,2) << "\n";
dist[gett(t,2)]=gett(t,1);
for(auto x:g[gett(t,2)]){
if(dist[x.ff]!=INF){
continue;
}
a.erase(mt(a1[x.ff],b1[x.ff],x.ff));
if(x.ss+dist[gett(t,2)]<a1[x.ff]){
b1[x.ff]=min(b1[x.ff],a1[x.ff]);
a1[x.ff]=x.ss+dist[gett(t,2)];
}
else if(x.ss+dist[gett(t,2)]<b1[x.ff]){
b1[x.ff]=x.ss+dist[gett(t,2)];
}
a.ins(mt(a1[x.ff],b1[x.ff],x.ff));
}
if(gett(t,2)==0){
break;
}
}
return dist[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |