이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define itr ::iterator
typedef pair<int,int> pii;
const int MAX=1e6;
const int INF=1e9+9;
vector<pii> vec[MAX];
ll mark[MAX],dp[MAX],deg[MAX];
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for(int A=0;A<M;A++)
{
vec[R[A][0]].pb(mp(R[A][1],L[A]));
vec[R[A][1]].pb(mp(R[A][0],L[A]));
}
priority_queue<pii,vector<pii>,greater<pii>> pq;
for(int A=0;A<K;A++)
{
deg[P[A]]=1;
pq.push(mp(0,P[A]));
}
while(!pq.empty())
{
pii cur=pq.top();
pq.pop();
deg[cur.second]++;
if(deg[cur.second]!=2)
continue;
dp[cur.second]=cur.first;
for(auto A:vec[cur.second])
if(deg[A.first]<2)
pq.push(mp(cur.first+A.second,A.first));
}
return dp[0];
}
/*signed main()
{
int N,M,K,R[MAX][2],L[MAX],P[MAX];
cin>>N>>M>>K;
for(int A=0;A<M;A++)
cin>>R[A][0]>>R[A][1]>>L[A];
for(int A=0;A<K;A++)
cin>>P[A];
cout<<travel_plan(N,M,R,L,K,P);
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... |