# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
626539 | Toqa44 | Alias (COCI21_alias) | C++17 | 40 ms | 472 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
ll n, m, ans, a, q , dis[1009] , pa[1009] , o;
string x, y ;
map<string ,ll>mp ;
vector<pair<ll,ll>>v[1009];
set <pair<ll,ll>> ss;
bool vis [1009];
int main()
{
ios::sync_with_stdio;cin.tie();cout.tie();
cin >> n >> m;
ll j = 1 ;
for(int i = 0; i < m ; i++)
{
cin >> x >> y >> a ;
if(mp[x] == 0)
{
mp[x] = j ;
j++ ;
}
if(mp[y] == 0)
{
mp[y] = j ;
j++ ;
}
v[mp[x]].push_back({mp[y],a});
}
cin >> q ;
while(q--)
{
ss.clear() ;
for( int i = 1 ; i <= n ; i++)
{
dis[i] = 1e18 ;
vis[i] = 0 ;
}
cin >> x >> y ;
ss.insert({0,mp[x]});
dis[mp[x]] = 0 ;
while(!ss.empty())
{
pair<ll,ll>u = *ss.begin();
ss.erase(u) ;
ll node = u.second ;
if(vis[node]) continue ;
vis[node] = 1 ;
for(auto p : v[node])
{
ll k = p.first ;
ll h = p.second ;
if(dis[k] > dis[node] + h)
{
pa[k] = node ;
dis[k] = dis[node] + h ;
ss.insert({dis[k],k}) ;
}
}
}
if(dis[mp[y]] == 1e18 )
cout << "Roger" << endl ;
else
cout << dis[mp[y]] << endl ;
}
return 0;
}
/*
3 2
novak goat 1
goat simulator 3
2
novak simulator
simulator goat
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |