Submission #966733

#TimeUsernameProblemLanguageResultExecution timeMemory
966733AliHasanliAlias (COCI21_alias)C++17
70 / 70
49 ms860 KiB
#include<bits/stdc++.h> using namespace std; vector<pair<int,long long>>g[1001]; bool used[1001]; long long dist[1001]; void dijkstra(int source) { priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>>pq; pq.push({0,source}); while(pq.size()) { long long cost=pq.top().first; int node=pq.top().second; pq.pop(); if(used[node])continue; used[node]=1; dist[node]=cost; for(pair<int,long long>go:g[node]) { if(used[go.first])continue; pq.push({go.second+cost,go.first}); } } } int main() { int n,m; cin>>n>>m; set<string>s; vector<pair<string,pair<string,long long>>>v; for(int i=0;i<m;i++) { string a,b; long long c; cin>>a>>b>>c; v.push_back({a,{b,c}}); s.insert(a); s.insert(b); } map<string,int>mp1; int ii=1; for(string i:s)mp1[i]=ii,ii++; for(pair<string,pair<string,long long>>i:v) g[mp1[i.first]].push_back({mp1[i.second.first],i.second.second}); int q; cin>>q; while(q--) { for(int i=0;i<1001;i++)dist[i]=1000000000000000000,used[i]=0; string s,e; cin>>s>>e; dijkstra(mp1[s]); if(dist[mp1[e]]==1000000000000000000)cout<<"Roger"<<endl; else cout<<dist[mp1[e]]<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...