Submission #476579

#TimeUsernameProblemLanguageResultExecution timeMemory
476579mychecksedadAlias (COCI21_alias)C++17
70 / 70
7 ms8396 KiB
#include<bits/stdc++.h> using namespace std; typedef long long int ll; #define pb push_back #define all(x) x.begin(), x.end() const int N = 1010, M = 1e5+10, F = 2147483646, K = 20; ll mx = 1e18; int n, m, cur=1; ll w, dp[N][N]; vector<pair<int, ll>> g[N]; map<string, int> ms; void dijkstra(int v){ for(int i = 1; i <= n; ++i){ dp[v][i] = mx; } dp[v][v] = 0; priority_queue<pair<ll, int>> q; q.push({0, v}); vector<bool> visited(n + 5, 0); while(!q.empty()){ int x = q.top().second; q.pop(); if(visited[x]) continue; visited[x] = 1; for(auto y: g[x]){ if(dp[v][y.first] > dp[v][x] + y.second){ dp[v][y.first] = dp[v][x] + y.second; q.push({-dp[v][y.first], y.first}); } } } } int main(){ cin.tie(0); ios::sync_with_stdio(0); cin >> n >> m; for(int i = 0; i < m; i++){ string s, s1; cin >> s >> s1 >> w; if(ms[s] == 0) ms[s] = cur++; if(ms[s1] == 0) ms[s1] = cur++; g[ms[s]].pb({ms[s1], w}); } for(int i = 1; i <= n; ++i){ dijkstra(i); } int q; cin >> q; while(q--){ string s, s1; cin >> s >> s1; ll ans = dp[ms[s]][ms[s1]]; if(ans == mx) cout << "Roger\n"; else cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...