# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
758965 | Adrian_Soriaga | Voting Cities (NOI22_votingcity) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pail;
vector<ll> dij(vector<pail> adj[] , int start ,int target , int nodes){
ll INF = 1000000000000000;
vector<ll> ans;
vector<int> done(nodes,0);
vector<ll> distance(nodes,INF);
priority_queue<pail, vector<pail>, greater<pail>> pq;
pq.push({0,start});
distance[start] = 0;
while (!pq.empty()){
ll u = pq.top().second;
pq.pop();
if (done[u]) continue;
done[u] =1;
for (auto x: adj[u]){
ll v = x.first , w = x.second;
if (distance[v] > distance[u]+ w) distance[v] = distance[u]+w;
pq.push({distance[v],v});
}
}
for (int i=0; i<n;i++) ans.push_back(distance[i]);
return ans;
}
int main(){
ll n,e,k; cin>>n>>e>>k;
int t; cin>>t;
vector<pail> adj[n];
for (int i=0; i<e;i++){
ll a,b,w; cin>>a>>b>>w;
adj[a].push_back({b,w});
//adj[b].push_back({a,w});
}
int q,s; cin>>q>>s;
vector<ll> check = dij(adj,t,s,n);
if (check[s] ==1000000000000000 ) cout<<-1<<"\n";
else cout<<check[s]<<"\n";
//getting the dummy tickets;
cin>>s>>s>>s>>s>>s;
for (int i=1; i<q; i++){
int t_1,t_2,t_3,t_4,t_5; cin>>s>>t_1>>t_2>>t_3>>t_4>>t_5;
if (check[s] ==1000000000000000 ) cout<<-1<<"\n";
else cout<<check[s]<<"\n";
}
}