Submission #421053

#TimeUsernameProblemLanguageResultExecution timeMemory
421053ChaskaAlias (COCI21_alias)C++11
70 / 70
132 ms47700 KiB
#include <bits/stdc++.h> #define F first #define S second using namespace std; typedef pair<int,int> i2; typedef vector<i2> vii; typedef pair<string,string> s2; typedef pair<s2,int> s3; const int N = 3e5+5; int n,m; vii g[N]; set<string> s; map<string,int> h; s3 a[N]; int q; s2 b[N]; bool vs[N]; int val[N]; priority_queue<i2,vii,greater<i2>> pq; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n >> m; for (int i=0;i<m;i++) { cin >> a[i].F.F >> a[i].F.S >> a[i].S; s.insert(a[i].F.F); s.insert(a[i].F.S); } cin >> q; for (int i=0;i<q;i++) { cin >> b[i].F >> b[i].S; s.insert(b[i].F); s.insert(b[i].S); } int cnt = 0; for (string u :s) h[u] = ++cnt; for (int i=0;i<m;i++) { g[h[a[i].F.F]].push_back({h[a[i].F.S],a[i].S}); } for (int i=0;i<q;i++) { for (int j=1;j<=n;j++) vs[j] = val[j] = 0; pq.push({0,h[b[i].F]}); while (!pq.empty()) { auto x = pq.top(); pq.pop(); if (!vs[x.S]) { vs[x.S] = true; val[x.S] = x.F; for (auto v : g[x.S]) { pq.push({x.F+v.S,v.F}); } } } if (val[h[b[i].S]] == 0) cout << "Roger\n"; else cout << val[h[b[i].S]] << "\n"; } return 0; }

Compilation message (stderr)

alias.cpp: In function 'int main()':
alias.cpp:41:47: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   41 |         for (int j=1;j<=n;j++) vs[j] = val[j] = 0;
      |                                        ~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...