Submission #715112

#TimeUsernameProblemLanguageResultExecution timeMemory
715112TheConverseEngineerAlias (COCI21_alias)C++17
70 / 70
30 ms468 KiB
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define sqr(x) ((ll)(x))*(x) typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; vector<pair<int, ll>> adj[1005]; ll dist[1005]; int N, M; ll INF = LLONG_MAX; void dijkstra(int start_node) { for (int i = 0; i < N; i++) dist[i] = INF; dist[start_node] = 0; priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq{}; pq.push({0ll,start_node}); while (!pq.empty()) { ll d; int node; tie(d, node) = pq.top(); pq.pop(); if (d != dist[node]) continue; for (auto u : adj[node]) { if (d+u.second < dist[u.first]) { dist[u.first] = d+u.second; pq.push({dist[u.first],u.first}); } } } } map<string, int> stringToNode; int node = 0; int main() { cin >> N >> M; FOR(i, 0, M) { string a, b; cin >> a >> b; if (stringToNode.count(a) == 0) stringToNode[a] = node++; if (stringToNode.count(b) == 0) stringToNode[b] = node++; int _a = stringToNode[a]; int _b = stringToNode[b]; ll _d; cin >> _d; adj[_a].push_back({_b, _d}); } int T; cin >> T; FOR(i, 0, T) { string a, b; cin >> a >> b; int _a = stringToNode[a]; int _b = stringToNode[b]; dijkstra(_a); if (dist[_b] == INF) cout << "Roger\n"; else cout << dist[_b] << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...