# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
736260 | rahidilbayramli | Alias (COCI21_alias) | C++17 | 21 ms | 852 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 ll long long
#define ld long double
#define pb push_back
#define vl vector<ll>
#define sl set<ll>
#define conn continue
#define tests while(t--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f first
#define s second
using namespace std;
const int sz = 1e4+5, inf = 1e9+7;
int dist[sz];
int n, m, i, j, l, c, q;
vector<pii>g[sz];
string a, b;
void dijkstra(int src)
{
for(i = 1; i <= n; i++) dist[i] = inf;
dist[src] = 0;
using T = pair<ll, int>;
priority_queue<T, vector<T>, greater<T>>pq;
pq.push({0ll, src});
while(!pq.empty())
{
int node;
ll cdist;
tie(cdist, node) = pq.top();
pq.pop();
if(cdist != dist[node]) continue;
for(const pii u : g[node])
{
if(cdist + u.s < dist[u.f])
{
dist[u.f] = cdist + u.s;
pq.push({dist[u.f], u.f});
}
}
}
}
int main()
{
int x, y;
map<string, ll>mp;
set<string>st;
cin >> n >> m;
for(i = 0; i < m; i++)
{
cin >> a >> b >> c;
l = st.size();
st.insert(a);
if(l != st.size()) mp[a] = st.size();
l = st.size();
st.insert(b);
if(l != st.size()) mp[b] = st.size();
x = mp[a], y = mp[b];
g[x].pb({y, c});
}
cin >> q;
while(q--)
{
cin >> a >> b;
x = mp[a], y = mp[b];
dijkstra(x);
if(dist[y] == inf) cout << "Roger\n";
else cout << dist[y] << "\n";
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |