Submission #600958

# Submission time Handle Problem Language Result Execution time Memory
600958 2022-07-21T09:34:20 Z nguyen31hoang08minh2003 Alias (COCI21_alias) C++14
70 / 70
6 ms 8532 KB
/*
\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /
\\    /\    //\\    /\    //\\    /\    //\\    /\    //\\    /\    //\\    /\    //\\    /\    //\\    /\    //\\    /\    //\\    /\    //
/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \
\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /
/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \
\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /
/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \
\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /
//    \/    \\//    \/    \\//    \/    \\//    \/    \\//    \/    \\//    \/    \\//    \/    \\//    \/    \\//    \/    \\//    \/    \\
/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \
\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /
\\    /\    //\\    /\    //\\    /\    //\\    /\    //\\    /\    //\\    /\    //\\    /\    //\\    /\    //\\    /\    //\\    /\    //
/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \
\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /
/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \
\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /
/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \
\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /
//    \/    \\//    \/    \\//    \/    \\//    \/    \\//    \/    \\//    \/    \\//    \/    \\//    \/    \\//    \/    \\//    \/    \\
/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \/     /\     \
*/
#include <bits/stdc++.h>
#define fore(i, a, b) for (int i = (a), i##_last = (b); i < i##_last; ++i)
#define fort(i, a, b) for (int i = (a), i##_last = (b); i <= i##_last; ++i)
#define ford(i, a, b) for (int i = (a), i##_last = (b); i >= i##_last; --i)
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using ld = long double;

template<class A, class B> bool maxi(A &a, const B &b) {return (a < b) ? (a = b, true):false;};
template<class A, class B> bool mini(A &a, const B &b) {return (a > b) ? (a = b, true):false;};

typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

#define maxN 1005
#define maxM 1005
const ll inf = 0X3F3F3F3F3F3F3F3F;

vii adj[maxN];
ll d[maxN][maxN];
int n, m, q, t[maxM];
string x[maxM], y[maxM];
unordered_map<string, int> words;

void subtask2() {
    fort(i, 1, m)
        mini(d[words[x[i]]][words[y[i]]], t[i]);
    fort(c, 1, n)
        fort(a, 1, n)
            fort(b, 1, n)
                mini(d[a][b], d[a][c] + d[c][b]);
}

void Dijkstra(int u, ll d[]) {
    priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int>> > pq;
    pq.emplace(d[u], u);
    while (!pq.empty()) {
        const auto [w, x] = pq.top();
        pq.pop();
        if (d[x] != w)
            continue;
        for (const auto &[w, y] : adj[x])
            if (mini(d[y], d[x] + w))
                pq.emplace(d[y], y);
    }
}

void subtask3() {
    fort(i, 1, m)
        adj[words[x[i]]].emplace_back(t[i], words[y[i]]);
    fort(i, 1, n)
        Dijkstra(i, d[i]);
}

int main() {
    #ifdef LOCAL
        freopen("input.INP", "r", stdin);
    #endif // LOCAL
    cin.tie(0) -> sync_with_stdio(0);
    cout.tie(0);
    memset(d, inf, sizeof(d));
    cin >> n >> m;
    fort(i, 1, m) {
        cin >> x[i] >> y[i] >> t[i];
        words[x[i]];
        words[y[i]];
    }
    n = 0;
    for (auto &[word, id] : words) {
        id = ++n;
        d[n][n] = 0;
    }
    if (n <= 200)
        subtask2();
    else
        subtask3();
    cin >> q;
    for (string a, b; q--;) {
        cin >> a >> b;
        const int &u = words[a], &v = words[b];
        if (d[u][v] >= inf)
            cout << "Roger\n";
        else
            cout << d[u][v] << '\n';
    }
    return 0;
}

Compilation message

alias.cpp: In function 'void Dijkstra(int, ll*)':
alias.cpp:70:20: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   70 |         const auto [w, x] = pq.top();
      |                    ^
alias.cpp:74:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   74 |         for (const auto &[w, y] : adj[x])
      |                          ^
alias.cpp: In function 'int main()':
alias.cpp:93:15: warning: overflow in conversion from 'll' {aka 'long long int'} to 'int' changes value from '4557430888798830399' to '1061109567' [-Woverflow]
   93 |     memset(d, inf, sizeof(d));
      |               ^~~
alias.cpp:101:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  101 |     for (auto &[word, id] : words) {
      |                ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8276 KB Output is correct
2 Correct 3 ms 8276 KB Output is correct
3 Correct 5 ms 8404 KB Output is correct
4 Correct 6 ms 8456 KB Output is correct
5 Correct 6 ms 8532 KB Output is correct
6 Correct 6 ms 8456 KB Output is correct
7 Correct 6 ms 8532 KB Output is correct