# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
517581 | kartel | Alias (COCI21_alias) | C++14 | 19 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 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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |