Submission #1127417


Source Code Expand

#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using int64 = int64_t;

using P = pair<int, int>;

constexpr int64 MOD = 1000000007;
constexpr int INF = MOD;

struct state {
    int pos, dist;
    state () {}
    state (int a, int b): pos(a), dist(b) {}
    bool operator < (const state &o) const { return dist > o.dist; }
};

struct edge {
    int to, dist, id;
    edge() {}
    edge(int b, int c, int id): to(b), dist(c), id(id) {}
};

int N, M;

vector<vector<edge>> graph;

vector<int> used;

// P = pair< `prev`, `edge_id` >
int main() {
    cin >> N >> M;
    graph.resize(N);
    used.resize(M);
    int edge_id = 0;
    for (int j = 0; j < M; ++j) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        graph[a].emplace_back(b, c, edge_id);
        graph[b].emplace_back(a, c, edge_id);
        edge_id++;
    }

    assert(edge_id == M);
    fill(begin(used), end(used), 0);

    vector<P> prev(N);
    for (int j = 0; j < N; ++j) {
        vector<int> dist(N);
        fill(begin(dist), end(dist), INF);
        fill(begin(prev), end(prev), make_pair(-1, -1));

        priority_queue<state> pq;
        pq.emplace(j, 0);
        dist[j] = 0;
        while (!pq.empty()) {
            state st = pq.top(); pq.pop();
            if (st.dist > dist[st.pos]) { continue; }

            for (const edge& e : graph[st.pos]) {
                if (st.dist + e.dist < dist[e.to]) {
                    dist[e.to] = st.dist + e.dist;
                    prev[e.to] = make_pair(st.pos, e.id);
                    pq.emplace(e.to, dist[e.to]);
                }
            }
        }

        for (int k = 0; k < N; ++k) {
            int pos = k;
            while (pos != j) {
                P p = prev[pos];
                used[p.second] = 1;
                pos = p.first;
            }
        }
    }

    int ans = 0;
    for (int j = 0; j < M; ++j) {
        if (!used[j]) {
            ++ans;
        }
    }
    cout << ans << endl;

    return 0;
}

Submission Info

Submission Time
Task D - Candidates of No Shortest Paths
User lrmystp
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2452 Byte
Status AC
Exec Time 4 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 30
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All sample_01.txt, sample_02.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt, subtask_1_19.txt, subtask_1_20.txt, subtask_1_21.txt, subtask_1_22.txt, subtask_1_23.txt, subtask_1_24.txt, subtask_1_25.txt, subtask_1_26.txt, subtask_1_27.txt, subtask_1_28.txt
Case Name Status Exec Time Memory
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
subtask_1_01.txt AC 1 ms 256 KB
subtask_1_02.txt AC 1 ms 256 KB
subtask_1_03.txt AC 2 ms 256 KB
subtask_1_04.txt AC 2 ms 256 KB
subtask_1_05.txt AC 3 ms 256 KB
subtask_1_06.txt AC 1 ms 256 KB
subtask_1_07.txt AC 1 ms 256 KB
subtask_1_08.txt AC 2 ms 256 KB
subtask_1_09.txt AC 2 ms 256 KB
subtask_1_10.txt AC 2 ms 256 KB
subtask_1_11.txt AC 1 ms 256 KB
subtask_1_12.txt AC 1 ms 256 KB
subtask_1_13.txt AC 2 ms 256 KB
subtask_1_14.txt AC 2 ms 256 KB
subtask_1_15.txt AC 2 ms 256 KB
subtask_1_16.txt AC 1 ms 256 KB
subtask_1_17.txt AC 1 ms 256 KB
subtask_1_18.txt AC 2 ms 256 KB
subtask_1_19.txt AC 2 ms 256 KB
subtask_1_20.txt AC 1 ms 256 KB
subtask_1_21.txt AC 1 ms 256 KB
subtask_1_22.txt AC 2 ms 256 KB
subtask_1_23.txt AC 2 ms 256 KB
subtask_1_24.txt AC 3 ms 256 KB
subtask_1_25.txt AC 3 ms 256 KB
subtask_1_26.txt AC 3 ms 256 KB
subtask_1_27.txt AC 4 ms 256 KB
subtask_1_28.txt AC 2 ms 256 KB