# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
486448 |
2021-11-11T17:04:37 Z |
davi_bart |
Alias (COCI21_alias) |
C++14 |
|
103 ms |
516 KB |
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define fi first
#define se second
#define ld long double
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
map<string, vector<pair<string, int>>> v;
string ans(string a, string b) {
priority_queue<pair<int, string>, vector<pair<int, string>>, greater<pair<int, string>>> q;
set<string> vis;
q.push({0, a});
while (!q.empty()) {
auto [d, pos] = q.top();
q.pop();
if (vis.count(pos)) continue;
vis.insert(pos);
if (pos == b) return to_string(d);
for (auto [x, y] : v[pos]) {
q.push({d + y, x});
}
}
return "Roger";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, M;
cin >> N >> M;
for (int i = 0; i < M; i++) {
string a, b;
int c;
cin >> a >> b >> c;
v[a].pb({b, c});
}
int Q;
cin >> Q;
while (Q--) {
string a, b;
cin >> a >> b;
cout << ans(a, b) << '\n';
}
}
Compilation message
alias.cpp: In function 'std::string ans(std::string, std::string)':
alias.cpp:17:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
17 | auto [d, pos] = q.top();
| ^
alias.cpp:22:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
22 | for (auto [x, y] : v[pos]) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
83 ms |
508 KB |
Output is correct |
4 |
Correct |
103 ms |
516 KB |
Output is correct |
5 |
Correct |
5 ms |
460 KB |
Output is correct |
6 |
Correct |
5 ms |
460 KB |
Output is correct |
7 |
Correct |
4 ms |
504 KB |
Output is correct |