Submission #245189

# Submission time Handle Problem Language Result Execution time Memory
245189 2020-07-05T16:43:18 Z Tc14 Toll (BOI17_toll) C++17
0 / 100
67 ms 5888 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ve vector
typedef long long ll;

int C;
ve<ve<pair<int, int>>> G;
ve<int> Comp, D;

void dfs(int u, int d, int c) {

    int v, t;

    Comp[u] = c;
    D[u] = d;

    for (pair<int, int> e : G[u]) {
        tie(v, t) = e;
        if (Comp[v] == 0) dfs(v, d + t, c);
    } 
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int k, n, m, o, a, b, t;

    cin >> k >> n >> m >> o;
    G = ve<ve<pair<int, int>>>(n);
    Comp = ve<int>(n);
    D = ve<int>(n);

    for (int i = 0; i < m; i++) {
        cin >> a >> b >> t;
        G[a].push_back({b, t});
    }

    C = 0;
    for (int i = 0; i < n; i++) {
        if (G[i].size() == 1) {
            if (Comp[i] == 0) {
                C++;
                dfs(i, 0, C);
            }
        }
    }

    for (int i = 0; i < o; i++) {
        cin >> a >> b;
        if (Comp[a] == Comp[b]) cout << abs(D[a] - D[b]) << endl;
        else cout << -1 << endl;
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 49 ms 5888 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 5 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 67 ms 4088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 49 ms 5888 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 5 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -