Submission #1192032

#TimeUsernameProblemLanguageResultExecution timeMemory
1192032SmuggingSpunAlias (COCI21_alias)C++20
70 / 70
12 ms1352 KiB
#include<bits/stdc++.h> #define taskname "B" using namespace std; typedef long long ll; unordered_map<string, vector<pair<string, int>>>g; unordered_map<string, unordered_map<string, ll>>d; unordered_map<string, bool>uni_str; int n, m; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); } cin >> n >> m; for(int i = 0; i < m; i++){ string x, y; int t; cin >> x >> y >> t; uni_str[x] = uni_str[y] = true; g[x].emplace_back(y, t); } for(auto& [root, foo] : uni_str){ priority_queue<pair<ll, string>, vector<pair<ll, string>>, greater<pair<ll, string>>>pq; pq.emplace(d[root][root] = 0, root); while(!pq.empty()){ auto [dis, u] = pq.top(); pq.pop(); if(d[root][u] == dis){ for(auto& [v, w] : g[u]){ ll W = dis + w; auto it = d[root].find(v); if(it == d[root].end() || (it->second) > W){ pq.emplace(d[root][v] = W, v); } } } } } int q; cin >> q; for(int _ = 0; _ < q; _++){ string u, v; cin >> u >> v; auto it = d[u].find(v); if(it == d[u].end()){ cout << "Roger\n"; continue; } cout << it->second << "\n"; } }

Compilation message (stderr)

alias.cpp: In function 'int main()':
alias.cpp:12:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...