# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
476579 | mychecksedad | Alias (COCI21_alias) | C++17 | 7 ms | 8396 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>
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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |