# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
421053 |
2021-06-08T16:55:02 Z |
Chaska |
Alias (COCI21_alias) |
C++11 |
|
132 ms |
47700 KB |
#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
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 time |
Memory |
Grader output |
1 |
Correct |
34 ms |
47300 KB |
Output is correct |
2 |
Correct |
31 ms |
47188 KB |
Output is correct |
3 |
Correct |
132 ms |
47516 KB |
Output is correct |
4 |
Correct |
126 ms |
47556 KB |
Output is correct |
5 |
Correct |
33 ms |
47700 KB |
Output is correct |
6 |
Correct |
34 ms |
47688 KB |
Output is correct |
7 |
Correct |
37 ms |
47612 KB |
Output is correct |