Submission #619313

#TimeUsernameProblemLanguageResultExecution timeMemory
619313Hussein3602Alias (COCI21_alias)C++14
70 / 70
186 ms3668 KiB
#include<bits/stdc++.h> using namespace std ; typedef long long ll ; const int N=1e5; int n , m , cnt=1 , q ; vector< pair<ll,ll> > edges[N] ; vector<ll>dist(N,-1) ; map<string,ll>mp ; ll bfs(int src, int traget) { set < pair<ll,ll> > s ; s.insert({0,src}) ; while(!s.empty()) { pair<ll,ll> p = *s.begin() ; s.erase(p) ; ll node=p.second , nodecost=p.first ; if(dist[node]!=-1)continue ; dist[node]=nodecost; for( pair<ll,ll> edge :edges[node]) { s.insert({nodecost+edge.second,edge.first}) ; } } if(dist[traget]!=-1)return dist[traget]; return -1; } int main() { cin >> n >> m ; for(int i=0;i<m;i++) { string x , y ; ll t ; cin >> x >> y >> t ; if(mp[x]==0)mp[x]=cnt++; if(mp[y]==0)mp[y]=cnt++; edges[mp[x]].push_back({mp[y],t}) ; } cin >> q ; while(q--) { string x , y ; cin >> x >> y ; ll d=bfs(mp[x],mp[y]) ; if(d==-1)cout<<"Roger"<<endl; else cout<<d<<endl; for(int i=0;i<=1000;i++)dist[i]=-1; } }
#Verdict Execution timeMemoryGrader output
Fetching results...