# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
812299 | Tunglam07 | Alias (COCI21_alias) | C++17 | 38 ms | 468 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;
map<string, int> mp;
vector<pair<int, int> > vec[1001];
long long dp[1001], cnt, n, m, q;
int ckstr(string x)
{
if (mp.find(x) == mp.end())
{
mp[x] = cnt++;
}
return mp[x];
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int t;
string x, y;
cin >> x >> y >> t;
vec[ckstr(x)].push_back(pair<int, int>(ckstr(y), t));
}
cin >> q;
while(q--)
{
string x, y;
cin >> x >> y;
set<pair<long long, int> > s;
memset(dp, -1, sizeof dp);
dp[ckstr(x)] = 0;
s.insert(pair<long long, int>(0, ckstr(x)));
while (!s.empty())
{
pair<long long, int> id = *s.begin();
s.erase(id);
int ckid = id.second;
for (int j = 0; j < (int)vec[ckid].size(); j++)
{
int nxt = vec[ckid][j].first;
int d = vec[ckid][j].second;
if (dp[nxt] == -1 || dp[nxt] > dp[ckid] + d)
{
s.erase(pair<long long, int>(dp[nxt], nxt));
dp[nxt] = dp[ckid] + d;
s.insert(pair<long long, int>(dp[nxt], nxt));
}
}
}
if (dp[ckstr(y)] == -1)
{
cout << "Roger" << endl;
}
else
{
cout << dp[ckstr(y)] << endl;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |