# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
386343 | model_code | Alias (COCI21_alias) | C++17 | 52 ms | 512 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <map>
#include <set>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
const int maxn = 1005;
int cnt;
map<string, int> ind_map;
int ind(string x) {
if (ind_map.find(x) == ind_map.end())
ind_map[x] = cnt++;
return ind_map[x];
}
int n, m, q;
vector<pii> e[maxn];
ll dist[maxn];
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 0; i < m; i++) {
int t;
string x, y;
cin >> x >> y >> t;
e[ind(x)].push_back(pii(ind(y), t));
}
cin >> q;
for (int i = 0; i < q; i++) {
string x, y;
cin >> x >> y;
set<pli> s;
memset(dist, -1, sizeof dist);
dist[ind(x)] = 0;
s.insert(pli(0, ind(x)));
while (!s.empty()) {
pli curr = *s.begin();
s.erase(curr);
int curr_ind = curr.second;
for (int j = 0; j < (int)e[curr_ind].size(); j++) {
int nxt = e[curr_ind][j].first;
int d = e[curr_ind][j].second;
if (dist[nxt] == -1 || dist[nxt] > dist[curr_ind] + d) {
s.erase(pli(dist[nxt], nxt));
dist[nxt] = dist[curr_ind] + d;
s.insert(pli(dist[nxt], nxt));
}
}
}
if (dist[ind(y)] == -1)
cout << "Roger" << endl;
else
cout << dist[ind(y)] << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |