# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
600958 | nguyen31hoang08minh2003 | Alias (COCI21_alias) | C++14 | 6 ms | 8532 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 fore(i, a, b) for (int i = (a), i##_last = (b); i < i##_last; ++i)
#define fort(i, a, b) for (int i = (a), i##_last = (b); i <= i##_last; ++i)
#define ford(i, a, b) for (int i = (a), i##_last = (b); i >= i##_last; --i)
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using ld = long double;
template<class A, class B> bool maxi(A &a, const B &b) {return (a < b) ? (a = b, true):false;};
template<class A, class B> bool mini(A &a, const B &b) {return (a > b) ? (a = b, true):false;};
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define maxN 1005
#define maxM 1005
const ll inf = 0X3F3F3F3F3F3F3F3F;
vii adj[maxN];
ll d[maxN][maxN];
int n, m, q, t[maxM];
string x[maxM], y[maxM];
unordered_map<string, int> words;
void subtask2() {
fort(i, 1, m)
mini(d[words[x[i]]][words[y[i]]], t[i]);
fort(c, 1, n)
fort(a, 1, n)
fort(b, 1, n)
mini(d[a][b], d[a][c] + d[c][b]);
}
void Dijkstra(int u, ll d[]) {
priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int>> > pq;
pq.emplace(d[u], u);
while (!pq.empty()) {
const auto [w, x] = pq.top();
pq.pop();
if (d[x] != w)
continue;
for (const auto &[w, y] : adj[x])
if (mini(d[y], d[x] + w))
pq.emplace(d[y], y);
}
}
void subtask3() {
fort(i, 1, m)
adj[words[x[i]]].emplace_back(t[i], words[y[i]]);
fort(i, 1, n)
Dijkstra(i, d[i]);
}
int main() {
#ifdef LOCAL
freopen("input.INP", "r", stdin);
#endif // LOCAL
cin.tie(0) -> sync_with_stdio(0);
cout.tie(0);
memset(d, inf, sizeof(d));
cin >> n >> m;
fort(i, 1, m) {
cin >> x[i] >> y[i] >> t[i];
words[x[i]];
words[y[i]];
}
n = 0;
for (auto &[word, id] : words) {
id = ++n;
d[n][n] = 0;
}
if (n <= 200)
subtask2();
else
subtask3();
cin >> q;
for (string a, b; q--;) {
cin >> a >> b;
const int &u = words[a], &v = words[b];
if (d[u][v] >= inf)
cout << "Roger\n";
else
cout << d[u][v] << '\n';
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |