# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
21909 | 2017-04-26T22:52:36 Z | iletavcioski | 악어의 지하 도시 (IOI11_crocodile) | C++ | 0 ms | 0 KB |
#include<iostream> #include<vector> #include<queue> #include<cstdio> using namespace std; typedef long long ll; bool oznaceni[100001]; struct node { int a; ll val; }; const bool operator <(const node &x,const node&y) { return x.val>y.val; } vector<vector<pair<int,ll> > > v; using namespace std; int main() { int n,m,k; cin>>n>>m>>k; vector<pair<int,ll> > vec; v.insert(v.begin(),n+1,vec); vector<ll> dist1(n+1,1e9+1); vector<ll> dist2(n+1,1e9+1); for(int i=0;i<m;i++) { int a,b; ll c; cin>>a>>b>>c; v[a].push_back(make_pair(b,c)); v[b].push_back(make_pair(a,c)); } priority_queue<node> pq; for(int i=0;i<k;i++) { int a; cin>>a; node g; g.a=a; g.val=0; pq.push(g); dist1[a]=dist2[a]=0; } while(!pq.empty()) { node g=pq.top(); pq.pop(); int topi=g.a; ll tops=g.val; for(int i=0;i<v[topi].size();i++) { if(tops+v[topi][i].second<dist1[v[topi][i].first]) { int go=v[topi][i].first; dist2[go]=dist1[go]; dist1[go]=tops+v[topi][i].second; node gg; gg.a=go; gg.val=dist2[go]; pq.push(gg); } else if(tops+v[topi][i].second<dist2[v[topi][i].first]) { int go=v[topi][i].first; dist2[go]=tops+v[topi][i].second; node gg; gg.a=go; gg.val=v[topi][i].second+tops; pq.push(gg); } } } cout<<dist2[0]<<endl; return 0; } /* 5 7 2 0 2 4 0 3 3 3 2 2 2 1 10 0 1 100 0 4 7 3 4 9 1 3 */