#include<bits/stdc++.h>
#define ll long long
#define vl vector<ll>
#define sl set<ll>
#define all(v) v.begin(), v.end()
#define f first
#define s second
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define tests while(t--)
using namespace std;
const ll sz = 1010;
vector<vector<ll>>graph(sz, vector<ll>(sz, 1e15));
ll n, m, i, j;
int main()
{
set<string>st;
map<string, ll>mp;
string a, b;
ll n, m, i, j, k, l, c, x, y, q;
cin >> n >> m;
for(i = 0; i < m; i++)
{
cin >> a >> b >> c;
l = st.size();
st.insert(a);
if(st.size() != l) mp[a] = st.size();
l = st.size();
st.insert(b);
if(st.size() != l) mp[b] = st.size();
x = mp[a];
y = mp[b];
c = min(c, graph[x][y]);
graph[x][y] = c;
}
for(i = 1; i <= n; i++) graph[i][i] = 0;
for(k = 1; k <= n; k++)
{
for(i = 1; i <= n; i++)
{
for(j = 1; j <= n; j++)
graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
}
}
cin >> q;
while(q--)
{
cin >> a >> b;
x = mp[a], y = mp[b];
if(graph[x][y] == 1e15) cout << "Roger\n";
else cout << graph[x][y] << "\n";
}
}
Compilation message
alias.cpp: In function 'int main()':
alias.cpp:28:22: warning: comparison of integer expressions of different signedness: 'std::set<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
28 | if(st.size() != l) mp[a] = st.size();
| ~~~~~~~~~~^~~~
alias.cpp:31:22: warning: comparison of integer expressions of different signedness: 'std::set<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
31 | if(st.size() != l) mp[b] = st.size();
| ~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8276 KB |
Output is correct |
2 |
Correct |
5 ms |
8276 KB |
Output is correct |
3 |
Correct |
11 ms |
8404 KB |
Output is correct |
4 |
Correct |
10 ms |
8404 KB |
Output is correct |
5 |
Correct |
850 ms |
8548 KB |
Output is correct |
6 |
Correct |
821 ms |
8552 KB |
Output is correct |
7 |
Execution timed out |
1028 ms |
8532 KB |
Time limit exceeded |