답안 #517571

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
517571 2022-01-23T06:06:27 Z kartel Alias (COCI21_alias) C++14
60 / 70
1000 ms 592 KB
#include <bits/stdc++.h>
#define pb push_back
#define el "\n"
using namespace std;
typedef long long ll;

map <string, vector <pair <string, int> > > g;
string x, y;
int t, n, m;

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> x >> y >> t;
        g[x].pb({y, t});
    }

    int q;
    cin >> q;
    while (q--) {
        cin >> x >> y;
        map <string, ll> d; d.clear();
        d[x] = 0;
        queue <string> q;
        q.push(x);
        while (q.size()) {
            string v = q.front(); q.pop();
            for (auto u : g[v]) {
                if (!d.count(u.first) || d[u.first] > d[v] + u.second) {
                    d[u.first] = d[v] + u.second;
                    q.push(u.first);
                }
            }
        }
        if (d.count(y)) {
            cout << d[y] << el;
        } else {
            cout << "Roger" << el;
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 420 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 914 ms 464 KB Output is correct
4 Execution timed out 1074 ms 492 KB Time limit exceeded
5 Correct 8 ms 592 KB Output is correct
6 Correct 8 ms 464 KB Output is correct
7 Correct 7 ms 528 KB Output is correct