Submission #517679

# Submission time Handle Problem Language Result Execution time Memory
517679 2022-01-23T06:49:06 Z ivls Alias (COCI21_alias) C++14
10 / 70
144 ms 17232 KB
#include <bits/stdc++.h>

using namespace std;

int n, m;
map<string, int> nn;
vector<int> g[5000];
int dst[5000][5000];

int dist(int st, int fi) {
    int dist[5000] = {};
    set<pair<int, int>> s;
    for (int i = 1; i <= n; i++) {
        s.insert(make_pair((i == st ? 0 : 2000000000), i));
        dist[i] = (i == st ? 0 : 2000000000);
    }
    while (!s.empty()) {
        int v = (*s.begin()).second;
        s.erase(s.begin());
        for (int u : g[v]) {
            if (dist[u] > dist[v] + dst[v][u]) {
                s.erase(make_pair(u, dist[u]));
                s.insert(make_pair(u, dist[v] + dst[v][u]));
                dist[u] = dist[v] + dst[v][u];
            }
        }
    }
    return dist[fi] == 2000000000 ? -1 : dist[fi];
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dst[i][j] = 2000000000;
        }
    }
    int ii = 0;
    for (int i = 0; i < m; i++) {
        string u, v;
        cin >> u >> v;
        int t;
        cin >> t;
        if (nn[u] == 0) {
            nn[u] = ++ii;
        }
        if (nn[v] == 0) {
            nn[v] = ++ii;
        }
        g[nn[u]].push_back(nn[v]);
        dst[nn[u]][nn[v]] = min(dst[nn[u]][nn[v]], t);
    }
    int qq;
    cin >> qq;
    while (qq--) {
        string a, b;
        cin >> a >> b;
        if (nn[a] == 0) {
            nn[a] = ++ii;
        }
        if (nn[b] == 0) {
            nn[b] = ++ii;
        }
        int r = dist(nn[a], nn[b]);
        if (r == -1) {
            cout << "Roger" << '\n';
        }
        else {
            cout << r << '\n';
        }
    }

    return 0;
} 
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Runtime error 3 ms 844 KB Execution killed with signal 11
3 Incorrect 48 ms 936 KB Output isn't correct
4 Runtime error 10 ms 2380 KB Execution killed with signal 11
5 Incorrect 144 ms 7728 KB Output isn't correct
6 Incorrect 121 ms 7724 KB Output isn't correct
7 Runtime error 24 ms 17232 KB Execution killed with signal 11