# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
736265 | rahidilbayramli | Alias (COCI21_alias) | C++17 | 23 ms | 468 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 vl vector<ll>
#define sl set<ll>
#define all(v) v.begin(), v.end()
#define f first
#define s second
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define tests while(t--)
using namespace std;
const ll sz = 1010, inf = 1e15;
ll dist[sz];
vector<pair<ll, int>>adj[sz];
int n, m, i, j;
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>>q;
q.push({0ll, src});
while(!q.empty())
{
int node;
ll cdist;
tie(cdist, node) = q.top();
q.pop();
if(cdist != dist[node]) continue;
for(auto u : adj[node])
{
if(cdist + u.s < dist[u.f])
{
dist[u.f] = cdist + u.s;
q.push({dist[u.f], u.f});
}
}
}
}
int main()
{
ll c, l, x, y, q;
string a, b;
cin >> n >> m;
set<string>st;
map<string, ll>mp;
for(i = 0; i < m; i++)
{
cin >> a >> b >> c;
l = st.size();
st.insert(a);
if(st.size() != l)
mp[a] = st.size();
l = st.size();
st.insert(b);
if(st.size() != l)
mp[b] = st.size();
x = mp[a], y = mp[b];
adj[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... |