Submission #517571

#TimeUsernameProblemLanguageResultExecution timeMemory
517571kartelAlias (COCI21_alias)C++14
60 / 70
1074 ms592 KiB
#include <bits/stdc++.h>
#define pb push_back
#define el "\n"
using namespace std;
typedef long long ll;

map <string, vector <pair <string, int> > > g;
string x, y;
int t, n, m;

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> x >> y >> t;
        g[x].pb({y, t});
    }

    int q;
    cin >> q;
    while (q--) {
        cin >> x >> y;
        map <string, ll> d; d.clear();
        d[x] = 0;
        queue <string> q;
        q.push(x);
        while (q.size()) {
            string v = q.front(); q.pop();
            for (auto u : g[v]) {
                if (!d.count(u.first) || d[u.first] > d[v] + u.second) {
                    d[u.first] = d[v] + u.second;
                    q.push(u.first);
                }
            }
        }
        if (d.count(y)) {
            cout << d[y] << el;
        } else {
            cout << "Roger" << el;
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...