이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define a first
#define b second
#define pb push_back
#include <crocodile.h>
llo mod=100000007;
int travel_plan(int n,int m,int r[][2],int l[],int k,int p[]){
int vis[n];
for(int i=0;i<n;i++){
vis[i]=0;
}
for(int i=0;i<k;i++){
vis[p[i]]=1;
}
vector<pair<int,int>> adj[n];
for(int i=0;i<m;i++){
adj[r[i][0]].pb({r[i][1],l[i]});
adj[r[i][1]].pb({r[i][0],l[i]});
}
int dist[n];
int dist2[n];
for(int i=0;i<n;i++){
dist[i]=-1;
dist2[i]=-1;
}
priority_queue<pair<int,int>> ac;
for(int i=0;i<n;i++){
if(vis[i]==1){
dist[i]=0;
dist2[i]=0;
ac.push({0,i});
}
}
while(ac.size()){
pair<int,int> no=ac.top();
ac.pop();
no.a=-no.a;
for(auto j:adj[no.b]){
int co=no.a+j.b;
if(dist[j.a]==-1 or dist[j.a]>co){
dist2[j.a]=dist[j.a];
dist[j.a]=co;
if(dist2[j.a]!=-1){
ac.push({-dist2[j.a],j.a});
}
}
else if(dist2[j.a]==-1 or dist2[j.a]>co){
dist2[j.a]=co;
ac.push({-dist2[j.a],j.a});
}
}
}
return dist2[0];
}
/*int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int aa[7][2];
int bb[7];
int cc[2];
cc[0]=1;cc[1]=3;
bb[0]=4;bb[1]=3;bb[2]=2;bb[3]=10;bb[4]=100;
bb[5]=7;bb[6]=9;
aa[0][0]=0;aa[0][1]=2;
aa[1][0]=0;aa[1][1]=3;
aa[2][0]=3;aa[2][1]=2;
aa[3][0]=2;aa[3][1]=1;
aa[4][0]=0;aa[4][1]=1;
aa[5][0]=0;aa[5][1]=4;
aa[6][0]=3;aa[6][1]=4;
int aa[4][2];
int bb[4];
int cc[3];
cc[0]=1;cc[1]=3;cc[2]=4;
bb[0]=2;bb[1]=3;bb[2]=1;bb[3]=4;
aa[0][0]=0;aa[0][1]=1;
aa[1][0]=0;aa[1][1]=2;
aa[2][0]=3;aa[2][1]=2;
aa[3][0]=2;aa[3][1]=4;
cout<<travel_plan(5,4,aa,bb,3,cc)<<endl;
return 0;
}*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |