Submission #386344

#TimeUsernameProblemLanguageResultExecution timeMemory
386344model_codeAlias (COCI21_alias)C++17
60 / 70
1094 ms8300 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18; vector<string> words; int index(string word) { for (int i = 0; i < (int)words.size(); i++) if (words[i] == word) return i; words.push_back(word); return (int)words.size() - 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<vector<ll>> dist(n, vector<ll>(n, INF)); for (int i = 0; i < n; i++) dist[i][i] = 0; while (m--) { string x, y; ll t; cin >> x >> y >> t; dist[index(x)][index(y)] = min(dist[index(x)][index(y)], t); } for (int k = 0; k < n; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); int q; cin >> q; while (q--) { string a, b; cin >> a >> b; ll sol = dist[index(a)][index(b)]; if (sol == INF) cout << "Roger\n"; else cout << sol << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...