Submission #517581

#TimeUsernameProblemLanguageResultExecution timeMemory
517581kartelAlias (COCI21_alias)C++14
70 / 70
19 ms472 KiB
#include <bits/stdc++.h> #define pb push_back #define el "\n" #pragma GCC optimize("unroll-loops") #pragma GCC optimize("Ofast") #pragma GCC optimize("-O3") using namespace std; typedef long long ll; const int N = 2e3 + 500; vector <pair <int, int> > g[N]; string x, y; int t, n, m, a, b; ll d[N]; map <string, int> num; int ptr = 0; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 0; i < m; i++) { cin >> x >> y >> t; if (num.count(x)) { a = num[x]; } else { num[x] = a = ptr++; } if (num.count(y)) { b = num[y]; } else { num[y] = b = ptr++; } g[a].pb({b, t}); } int q; cin >> q; while (q--) { cin >> x >> y; a = num[x]; b = num[y]; for (int i = 0; i < ptr; i++) { d[i] = 1e18; } d[a] = 0; queue <int> q; q.push(a); while (q.size()) { int v = q.front(); q.pop(); for (auto u : g[v]) { if (d[u.first] > d[v] + u.second) { d[u.first] = d[v] + u.second; q.push(u.first); } } } if (d[b] != (ll)1e18) { cout << d[b] << el; } else { cout << "Roger" << el; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...