# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
919789 | abcdefghijk123 | Alias (COCI21_alias) | C++14 | 16 ms | 604 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 pair<int, int> pi;
const int MM = 1002;
int intN, intM;
//int dis[MM];
vector<pi> adj[MM];
//bool vis[MM];
int dis[MM];
bool vis[MM];
int function1(int start, int end) {
fill(dis, dis + intN, 0x3f3f3f3f);
fill(vis, vis + intN, false);
priority_queue<pi, vector<pi>, greater<pi>> q;
dis[start] = 0;
q.push({0, start});
while(!q.empty()){
auto [d, u] = q.top();
q.pop();
if(vis[u]) continue;
vis[u] = true;
for(auto [v, w] : adj[u]){
if(dis[v] > dis[u] + w){
dis[v] = dis[u] + w;
q.push({dis[v], v});
}
}
}
return dis[end];
}
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
unordered_map<string, int> mp;
cin >> intN >> intM;
for (int i = 0; i < intM; i++) {
string x, y, z;
cin >> x >> y >> z;
if(!mp.count(x)) mp[x] = mp.size();
if(!mp.count(y)) mp[y] = mp.size();
adj[mp[x]].push_back({mp[y],stoi(z)});
//adj[y].push_back({x,z});
}
int intQ;
cin >> intQ;
for (int i = 0; i < intQ; i++) {
string x, y;
cin >> x >> y;
int index = mp[x];
int index1 = mp[y];
int aaa = function1(index,index1);
if(aaa > 1000000000) {
cout << "Roger" << "\n";
} else {
cout << aaa << "\n";
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |