Submission #447903

#TimeUsernameProblemLanguageResultExecution timeMemory
447903JasiekstrzAlias (COCI21_alias)C++17
70 / 70
24 ms460 KiB
#include<bits/stdc++.h> #define fi first #define se second using namespace std; const int N=1e3; const long long INF=1e18L+7; int idit=0; map<string,int> id; vector<pair<int,int>> e[N+10]; long long d[N+10]; int getid(string x) { if(id.find(x)==id.end()) id[x]=++idit; return id[x]; } void dijkstra(int x) { priority_queue<pair<long long,int>> pq; d[x]=0; pq.emplace(0,x); while(!pq.empty()) { auto [dd,y]=pq.top(); pq.pop(); if(d[y]!=-dd) continue; for(auto [v,c]:e[y]) { if(d[v]>d[y]+c) { d[v]=d[y]+c; pq.emplace(-d[v],v); } } } return; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,m,q; cin>>n>>m; for(int i=1;i<=m;i++) { string a,b; int c; cin>>a>>b>>c; e[getid(a)].emplace_back(getid(b),c); } cin>>q; while(q--) { string a,b; cin>>a>>b; for(int i=1;i<=n;i++) d[i]=INF; dijkstra(getid(a)); if(d[getid(b)]==INF) cout<<"Roger\n"; else cout<<d[getid(b)]<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...