Submission #245190

# Submission time Handle Problem Language Result Execution time Memory
245190 2020-07-05T16:48:10 Z Tc14 Toll (BOI17_toll) C++17
0 / 100
77 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 (Comp[i] == 0) {
            C++;
            dfs(i, 0, C);
        }
    }

    cout << C << endl;

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

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 5888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 4216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 5888 KB Output isn't correct
2 Halted 0 ms 0 KB -