Submission #1774835


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
const int M = 1000000007;

int main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    --s;
    --t;
    vector<vector<int>> edge(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        scanf("%d%d", &a, &b);
        --a;
        --b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vector<int> ds(n, -1);
    vector<int> cs(n, 0);
    queue<int> q;
    q.push(s);
    ds[s] = 0;
    ++cs[0];
    while (!q.empty()) {
        int p = q.front();
        q.pop();
        for (int i : edge[p]) {
            if (ds[i] == -1) {
                ds[i] = ds[p] + 1;
                ++cs[ds[i]];
                q.push(i);
            }
        }
    }
    vector<int> dt(n, -1);
    vector<int> ct(n, 0);
    q.push(t);
    dt[t] = 0;
    ++ct[0];
    while (!q.empty()) {
        int p = q.front();
        q.pop();
        for (int i : edge[p]) {
            if (dt[i] == -1) {
                dt[i] = dt[p] + 1;
                ++ct[dt[i]];
                q.push(i);
            }
        }
    }
    int l = ds[t] - 1;
    long long ans = 0;
    for (int i = 0; i <= l; ++i)
        ans += cs[i] * (long long)ct[l - i - 1];

    cout << ans << "\n";
    return 0;
}

Submission Info

Submission Time
Task B - Minus One
User riantkb
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1305 Byte
Status AC
Exec Time 63 ms
Memory 8312 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:13:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a, &b);
                              ^

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 73
Set Name Test Cases
All 00-sample1.txt, 00-sample2.txt, 00-sample4.txt, 50-random10.txt, 50-random11.txt, 50-random12.txt, 50-random13.txt, 50-random14.txt, 50-random15.txt, 50-random16.txt, 50-random17.txt, 50-random18.txt, 50-random19.txt, 50-random20.txt, 50-random21.txt, 50-random22.txt, 50-random23.txt, 50-random24.txt, 50-random25.txt, 50-random26.txt, 50-random27.txt, 50-random28.txt, 50-random29.txt, 50-random30.txt, 50-random31.txt, 50-random32.txt, 50-random33.txt, 50-random34.txt, 50-random35.txt, 50-random36.txt, 50-random37.txt, 50-random38.txt, 50-random39.txt, 50-random40.txt, 50-random41.txt, 50-random42.txt, 50-random43.txt, 50-random44.txt, 50-random45.txt, 50-random46.txt, 50-random47.txt, 50-random48.txt, 50-random49.txt, 50-random50.txt, 50-random51.txt, 50-random52.txt, 50-random53.txt, 50-random54.txt, 50-random55.txt, 50-random56.txt, 50-random57.txt, 50-random58.txt, 50-random59.txt, 50-random60.txt, 50-random61.txt, 50-random62.txt, 50-random63.txt, 50-random64.txt, 50-random65.txt, 50-random66.txt, 50-random67.txt, 50-random68.txt, 50-random69.txt, intoverflow00.txt, intoverflow01.txt, intoverflow02.txt, intoverflow03.txt, intoverflow04.txt, intoverflow05.txt, intoverflow06.txt, intoverflow07.txt, intoverflow08.txt, intoverflow09.txt
Case Name Status Exec Time Memory
00-sample1.txt AC 1 ms 256 KB
00-sample2.txt AC 1 ms 256 KB
00-sample4.txt AC 1 ms 256 KB
50-random10.txt AC 1 ms 256 KB
50-random11.txt AC 1 ms 256 KB
50-random12.txt AC 1 ms 256 KB
50-random13.txt AC 1 ms 256 KB
50-random14.txt AC 1 ms 256 KB
50-random15.txt AC 1 ms 256 KB
50-random16.txt AC 1 ms 256 KB
50-random17.txt AC 1 ms 256 KB
50-random18.txt AC 1 ms 256 KB
50-random19.txt AC 1 ms 256 KB
50-random20.txt AC 1 ms 256 KB
50-random21.txt AC 1 ms 256 KB
50-random22.txt AC 1 ms 256 KB
50-random23.txt AC 1 ms 256 KB
50-random24.txt AC 1 ms 256 KB
50-random25.txt AC 1 ms 256 KB
50-random26.txt AC 1 ms 256 KB
50-random27.txt AC 1 ms 256 KB
50-random28.txt AC 1 ms 256 KB
50-random29.txt AC 1 ms 256 KB
50-random30.txt AC 1 ms 256 KB
50-random31.txt AC 1 ms 256 KB
50-random32.txt AC 1 ms 256 KB
50-random33.txt AC 1 ms 256 KB
50-random34.txt AC 1 ms 256 KB
50-random35.txt AC 1 ms 256 KB
50-random36.txt AC 1 ms 256 KB
50-random37.txt AC 1 ms 256 KB
50-random38.txt AC 1 ms 256 KB
50-random39.txt AC 1 ms 256 KB
50-random40.txt AC 2 ms 384 KB
50-random41.txt AC 1 ms 256 KB
50-random42.txt AC 2 ms 256 KB
50-random43.txt AC 1 ms 256 KB
50-random44.txt AC 2 ms 256 KB
50-random45.txt AC 1 ms 256 KB
50-random46.txt AC 2 ms 256 KB
50-random47.txt AC 2 ms 256 KB
50-random48.txt AC 2 ms 256 KB
50-random49.txt AC 2 ms 256 KB
50-random50.txt AC 3 ms 640 KB
50-random51.txt AC 7 ms 896 KB
50-random52.txt AC 3 ms 384 KB
50-random53.txt AC 6 ms 1024 KB
50-random54.txt AC 7 ms 1024 KB
50-random55.txt AC 8 ms 1024 KB
50-random56.txt AC 2 ms 256 KB
50-random57.txt AC 4 ms 768 KB
50-random58.txt AC 3 ms 640 KB
50-random59.txt AC 3 ms 512 KB
50-random60.txt AC 40 ms 4736 KB
50-random61.txt AC 38 ms 4352 KB
50-random62.txt AC 62 ms 6016 KB
50-random63.txt AC 38 ms 4224 KB
50-random64.txt AC 42 ms 5120 KB
50-random65.txt AC 15 ms 2048 KB
50-random66.txt AC 14 ms 2560 KB
50-random67.txt AC 6 ms 2816 KB
50-random68.txt AC 5 ms 768 KB
50-random69.txt AC 4 ms 1920 KB
intoverflow00.txt AC 63 ms 8312 KB
intoverflow01.txt AC 62 ms 8308 KB
intoverflow02.txt AC 60 ms 8304 KB
intoverflow03.txt AC 59 ms 8312 KB
intoverflow04.txt AC 61 ms 8308 KB
intoverflow05.txt AC 62 ms 8308 KB
intoverflow06.txt AC 59 ms 8308 KB
intoverflow07.txt AC 60 ms 8312 KB
intoverflow08.txt AC 62 ms 8312 KB
intoverflow09.txt AC 59 ms 8312 KB