Problem:
イクタ君は、無向グラフについて異常なほどの思い入れを持っている。イクタ君は、無向グラフ
G
とその 2 点
s,t
の組
(G,s,t)
のうち、その「うつくしさ」が大きいものが好きである。
組
(G,s,t)
の「うつくしさ」とは、辺
e = \{u, v\}
(
u
と
v
は
G
の異なる 2 点) で、
G
における
s
から
t
への最短路の長さが、
G
に
e
をつけくわえた無向グラフにおける
s
から
t
への最短路の長さより 1 だけ大きいものの個数である。
あなたの仕事は、組
(G,s,t)
が与えられたとき、その「うつくしさ」を求めるプログラムを書くことである。
Input
入力は以下の形式で与えられる。
N
M
s
t
x
1
y
1
...
x
i
y
i
...
x
M
y
M
最初に無向グラフの頂点数、辺数、2つの頂点を表す整数
N,M,s,t
が入力される。
2行目から
M+1
行目までは辺によって結ばれている2つの頂点が入力される。
(ただし、
G
の頂点集合を
\{1,
...
, N\}
とする。)
Constraints
入力中の各変数は以下の制約を満たす。
2≤ N ≤ 100,000
1≤ M ≤ 300,000
1≤ s,t,x
i
,y
i
≤ N
s
と
t
とは異なる
s
から
t
に辿り着けることは保証されている
Output
与えられたグラフを
G
としたとき、組
(G,s,t)
の「うつくしさ」を1行で出力せよ。
Sample Input 1
3 2 1 3
1 2
2 3
Output for the Sample Input 1
1
頂点1から頂点3に辺を張ると、2点間の最短距離が 1 短くなる。
Sample Input 2
9 8 7 8
2 6
4 9
8 6
9 2
3 8
1 8
8 5
7 9
Output for the Sample Input 2
7
Sample Input 3
4 3 1 4
1 2
3 4
4 1
Output for the Sample Input 3
0
頂点1と頂点4には既に辺が張られているので、これ以上距離を縮めることはできない。
Sample Input 4
9 7 8 9
9 6
6 5
3 6
3 7
2 5
8 5
1 4
Output for the Sample Input 4
2

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = (r)-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n,m,S,T;cin >> n >> m >> S >> T;
  S--;T--;
  vvi v(n);
  rep(i,0,m){
    int a,b;cin >> a >> b;
    a--;b--;
    v[a].emplace_back(b);
    v[b].emplace_back(a);
  }
  auto bfs = [&](int ST){
    vi d(n,-1);d[ST] = 0;
    queue<int> que;
    que.push(ST);
    while(sz(que)){
      int ov = que.front();que.pop();
      for(auto nv : v[ov]){
        if(d[nv] != -1)continue;
        d[nv] = d[ov] + 1;
        que.push(nv);
      }
    }
    return d;
  };
  vi d(bfs(S)),rd(bfs(T));
  vi C(n+1);
  rep(i,0,n)if(rd[i] >= 0)C[rd[i]]++;
  ll res = 0;
  rep(i,0,n)if(d[i] >= 0 && d[T]-d[i]-2 >= 0)res += C[d[T]-d[i]-2];
  cout << res << endl;
  

  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 12792
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) a.begin(),a.end()
#define reps(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, a, n) for (int i = (a); i > (int)(n); i--)
const long long mod = 1000000007;
const long long INF = 1e18;
ll myceil(ll a, ll b) {return (a+b-1)/b;}

template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }




void solve() {
    ll n,m,s,t;
    cin >> n >> m >> s >> t;
    s--;
    t--;
    vector<vector<int>> v(n);
    int x,y;
    rep(i,m) {
        cin >> x >> y;
        x--; y--;
        v[x].push_back(y);
        v[y].push_back(x);
    }

    vector<ll> djs (n,INF), djt(n,INF);

    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;

    djs[s] = 0;
    pq.push({0,s});
    while (!pq.empty()) {
        auto p = pq.top();
        pq.pop();
        if (p.first != djs[p.second]) continue;

        int d = p.first;
        int fr = p.second;

        for (auto x : v[fr]) {
            if (djs[x] > d+1) {
                djs[x] = d+1;
                pq.push({d+1,x});
            }
        }
    }



    djt[t] = 0;
    pq.push({0,t});
    while (!pq.empty()) {
        auto p = pq.top();
        pq.pop();
        if (p.first != djt[p.second]) continue;

        int d = p.first;
        int fr = p.second;

        for (auto x : v[fr]) {
            if (djt[x] > d+1) {
                djt[x] = d+1;
                pq.push({d+1,x});
            }
        }
    }


    int sub = djs[t];

    vector<ll> vs(100010,0), vt(100010,0);

    rep(i,n) {
        if (djs[i] != INF) vs[djs[i]]++;
        if (djt[i] != INF) vt[djt[i]]++;
    }

    ll ans = 0;

    rep(i,sub-1) {
        ans += vs[i]*vt[sub-2-i];
    }
    cout << ans << endl;
    return;

}


int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    solve();

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 13316
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

class Dijkstra {
  private:
    struct edge {
        int from, to;
        long long cost;
    };
    int n;
    vector<long long> dist;
    vector<vector<edge>> G;

  public:
    Dijkstra(int n_) : n(), dist(n_), G(n_) {}
    void add_edge(int u, int v, long long w) {
        edge e;
        e.to = v, e.cost = w;
        G[u].push_back(e);
    }
    void build(int s) {
        using P = pair<long long, int>;
        priority_queue<P, vector<P>, std::greater<P>> que;
        fill(dist.begin(), dist.end(), 3e18);
        dist[s] = 0;
        que.push(P(0, s));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (dist[v] < p.first)
                continue;
            for (int i = 0; i < (signed)G[v].size(); i++) {
                edge e = G[v][i];
                if (dist[e.to] > dist[v] + e.cost) {
                    dist[e.to] = dist[v] + e.cost;
                    que.push(P(dist[e.to], e.to));
                }
            }
        }
    }
    long long get(int v) { return dist[v]; }
};

void solve() {
    int N, M, S, T;
    cin >> N >> M >> S >> T;
    vector<int> X(M), Y(M);
    Dijkstra g(N), g2(N);
    for (int i = 0; i < M; i++) {
        cin >> X[i] >> Y[i];
        X[i]--, Y[i]--;
        g.add_edge(X[i], Y[i], 1);
        g.add_edge(Y[i], X[i], 1);
        g2.add_edge(X[i], Y[i], 1);
        g2.add_edge(Y[i], X[i], 1);
    }
    S--, T--;
    g.build(S);
    g2.build(T);
    vector<long long> dist(N + 10), dist2(N + 10);
    long long mmax = g.get(T);
    for (int i = 0; i < N; i++) {
        if (g.get(i) != 3e18) {
            dist[g.get(i)]++;
        }
        if (g2.get(i) != 3e18) {
            dist2[g2.get(i)]++;
        }
    }
    long long ans = 0;
    for (int i = 0; i <= mmax - 2; i++) {
        ans += dist[i] * dist2[mmax - 2 - i];
    }
    cout << ans << endl;
}

int main() {
    // while (1) {
    solve();
    //}
    return 0;
}
accuracy: 1
time_ms: 120
memory_kb: 29484
final_rank: 16

code_snippet: // (⁠◕⁠ᴗ⁠◕⁠✿⁠)

// #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define srep(i, s, n) for (ll i = s; i < (n); i++)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using vvv = vv<vc<T>>;
using vi = vc<int>;using vvi = vv<int>; using vvvi = vv<vi>;
using ll = long long;using vl = vc<ll>;using vvl = vv<ll>; using vvvl = vv<vl>;
using ld = long double; using vld = vc<ld>; using vvld = vc<vld>; using vvvld = vc<vvld>;
using uint = unsigned int;
using ull = unsigned long long;
const ld pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll mod = 1000000007;
const ll mod = 998244353;
inline bool inside(ll y, ll x, ll H, ll W) {return 0 <= (y) and (y) < (H) and 0 <= (x) and (x) < (W); }

#define debug(var) do { cout << #var << " :\n"; view(var); } while(0)
template<typename T>void view(const T& e) {cout << e;}
template<typename T1, typename T2>void view(const pair<T1, T2>& p) {cout << "{" << p.first << ", " << p.second << "}";}
template<typename T>void view(const vc<T>& v) {for (const auto& e : v) {view(e);cout << " ";} cout << endl;}
template<typename T>void view(const vv<T>& vv) {for (const auto& v : vv) {view(v);cout << " ";} cout << endl;}
template<typename T>void view(const set<T>& s) {for (const auto& e : s) {view(e);cout << " ";} cout << endl;}
template<typename T>void view(const unordered_set<T>& s) {for (const auto& e : s) {view(e);cout << " ";} cout << endl;}
template<typename T1, typename T2>void view(const map<T1, T2>& mp){for (const auto& e : mp) {view(e);cout << " ";} cout << endl;}

tuple<vl, vi> dijkstra(int s, int N, vv<pair<int, ll>> &g){
    using P = pair<ll, int>;
    vl dist(N, INF);
    vi bef(N);
    priority_queue<P, vc<P>, greater<P>> q;
    dist[s] = 0;
    q.push({0, s});
    while (!q.empty()){
        auto [c, now] = q.top();q.pop();
        if (dist[now] < c) continue;
        for (auto&& [nxt, nc]: g[now]) if (dist[nxt] > c + nc){
            dist[nxt] = c + nc;
            bef[nxt] = now;
            q.push({dist[nxt], nxt}); 
        }
    }
    return {dist, bef};
}


int main(){
    int N, M, s, t; cin >> N >> M >> s >> t; s--; t--;
    vv<pair<int, ll>> g(N);
    rep(i, M){
        int a, b; cin >> a >> b; a--; b--;
        g[a].push_back({b, 1});
        g[b].push_back({a, 1});
    }
    auto [dist_s, _] = dijkstra(s, N, g);
    auto [dist_t, __] = dijkstra(t, N, g);
    vi cnt(N, 0);
    rep(i, N) if (dist_s[i] < N) cnt[dist_s[i]]++;
    ll ans = 0;
    rep(i, N){
        int p = dist_s[t] - dist_t[i] - 2;
        if (0 <= p) ans += cnt[p];
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 70
memory_kb: 18804
final_rank: 15

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

int main() {
    int N, M, S, T;
    cin >> N >> M >> S >> T;
    S--, T--;
    vector<vector<int>> G(N);
    rep(i,0,M) {
        int X, Y;
        cin >> X >> Y;
        X--, Y--;
        G[X].push_back(Y);
        G[Y].push_back(X);
    }
    auto MakeDist = [&](int Start) -> vector<int> {
        vector<int> Ret(N,inf);
        Ret[Start] = 0;
        queue<int> Q;
        Q.push(Start);
        while(!Q.empty()) {
            int P = Q.front();
            Q.pop();
            for (int NP : G[P]) {
                if (chmin(Ret[NP],Ret[P]+1)) {
                    Q.push(NP);
                }
            }
        }
        return Ret;
    };
    auto D1 = MakeDist(S), D2 = MakeDist(T);
    int D = D1[T];
    vector<ll> COUNT1(N,0), COUNT2(N,0);
    rep(i,0,N) {
        if (D1[i] == inf) continue;
        COUNT1[D1[i]]++;
    }
    rep(i,0,N) {
        if (D2[i] == inf) continue;
        COUNT2[D2[i]]++;
    }
    ll ANS = 0;
    rep(i,0,D-1) {
        ANS += COUNT1[i] * COUNT2[D-2-i];
    }
    cout << ANS << endl;
}
accuracy: 1
time_ms: 70
memory_kb: 12004
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, a, b) for(ll i = a; i < b; ++i)
#define rrep(i, a, b) for(ll i = a; i >= b; --i)
constexpr ll inf = 4e18;
struct SetupIO {
    SetupIO() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout << fixed << setprecision(30);
    }
} setup_io;
int main(void) {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--;
    t--;
    vector<vector<int>> g(n);
    rep(i, 0, m) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    auto dijkstra = [&](int s) -> vector<int> {
        vector<int> d(n, 1e9);
        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
        d[s] = 0;
        pq.push({d[s], s});
        while(!pq.empty()) {
            auto [dist, cur] = pq.top();
            pq.pop();
            if(d[cur] < dist) continue;
            for(int to : g[cur]) {
                if(d[to] > d[cur] + 1) {
                    d[to] = d[cur] + 1;
                    pq.push({d[to], to});
                }
            }
        }
        return d;
    };
    vector<int> ds = dijkstra(s), dt = dijkstra(t);
    vector<ll> cnts(n), cntt(n);
    rep(i, 0, n) {
        if(ds[i] < n) cnts[ds[i]]++;
        if(dt[i] < n) cntt[dt[i]]++;
    }
    ll ans = 0;
    rep(i, 0, ds[t] - 1) {
        ans += cnts[i] * cntt[ds[t] - i - 2];
    }
    cout << ans << '\n';
}
accuracy: 1
time_ms: 40
memory_kb: 11736
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, a, b) for(ll i = a; i < b; ++i)
#define rrep(i, a, b) for(ll i = a; i >= b; --i)
constexpr ll inf = 4e18;
struct SetupIO {
    SetupIO() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout << fixed << setprecision(30);
    }
} setup_io;
int main(void) {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--;
    t--;
    vector<vector<int>> g(n);
    rep(i, 0, m) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    auto dijkstra = [&](int s) -> vector<int> {
        vector<int> d(n, 1e9);
        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
        d[s] = 0;
        pq.push({d[s], s});
        while(!pq.empty()) {
            auto [dist, cur] = pq.top();
            pq.pop();
            if(d[cur] < dist) continue;
            for(int to : g[cur]) {
                if(d[to] > d[cur] + 1) {
                    d[to] = d[cur] + 1;
                    pq.push({d[to], to});
                }
            }
        }
        return d;
    };
    vector<int> ds = dijkstra(s), dt = dijkstra(t);
    vector<int> cnts(n), cntt(n);
    rep(i, 0, n) {
        if(ds[i] < n) cnts[ds[i]]++;
        if(dt[i] < n) cntt[dt[i]]++;
    }
    ll ans = 0;
    rep(i, 0, ds[t] - 1) {
        ans += cnts[i] * cntt[ds[t] - i - 2];
    }
    cout << ans << '\n';
}
accuracy: 0.863013698630137
time_ms: 40
memory_kb: 10864
final_rank: 17

code_snippet: #include <iostream>
#include <queue>
#include <vector>
#define INF (1 << 23)
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int N, M, s, t, u, v;
  cin >> N >> M >> s >> t;

  s--;
  t--;

  vector<vector<int>> G(N);
  for (int i = 0; i < M; i++) {
    cin >> u >> v;
    G[u - 1].emplace_back(v - 1);
    G[v - 1].emplace_back(u - 1);
  }

  vector<int> d1(N, INF);
  d1[s] = 0;

  vector<int> d2(N, INF);
  d2[t] = 0;

  queue<int> que;
  que.push(s);
  while (!que.empty()) {
    int node = que.front();
    que.pop();
    int size = G[node].size();
    for (int i = 0; i < size; i++) {
      if (d1[G[node][i]] == INF) {
        d1[G[node][i]] = d1[node] + 1;
        que.push(G[node][i]);
      }
    }
  }

  que.push(t);
  while (!que.empty()) {
    int node = que.front();
    que.pop();
    int size = G[node].size();
    for (int i = 0; i < size; i++) {
      if (d2[G[node][i]] == INF) {
        d2[G[node][i]] = d2[node] + 1;
        que.push(G[node][i]);
      }
    }
  }

  int shortest = d1[t];
  vector<int> r1(shortest - 1, 0);
  vector<int> r2(shortest - 1, 0);

  for (int i = 0; i < N; i++) {
    if (d1[i] < shortest - 1) {
      r1[d1[i]]++;
    }
    if (d2[i] < shortest - 1) {
      r2[d2[i]]++;
    }
  }

  long long ret = 0;
  for (int i = 0; i < shortest - 1; i++) {
    ret += 1LL * r1[i] * r2[shortest - i - 2];
  }
  cout << ret << '\n';
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 10440
final_rank: 4

code_snippet: #include <functional>
#include <iostream>
#include <queue>
#include <vector>
#define INF (1 << 23)
using namespace std;

int main() {
    int N, M, s, t, u, v;
    scanf("%d", &N);
    scanf("%d", &M);
    scanf("%d", &s);
    s--;
    scanf("%d", &t);
    t--;
    vector<vector<int>> G(N);
    for (int i = 0; i < M; i++) {
        scanf("%d", &u);
        scanf("%d", &v);
        G[u - 1].push_back(v - 1);
        G[v - 1].push_back(u - 1);
    }
    vector<int> d1(N, INF);
    d1[s] = 0;
    vector<int> d2(N, INF);
    d2[t] = 0;
    queue<int> que;
    que.push(s);
    while (!que.empty()) {
        int node = que.front();
        que.pop();
        int nodeSize = G[node].size(); // avoid repeated computation
        for (int i = 0; i < nodeSize; i++) {
            if (d1[G[node][i]] == INF) {
                d1[G[node][i]] = d1[node] + 1;
                que.push(G[node][i]);
            }
        }
    }
    que.push(t);
    while (!que.empty()) {
        int node = que.front();
        que.pop();
        int nodeSize = G[node].size(); // avoid repeated computation
        for (int i = 0; i < nodeSize; i++) {
            if (d2[G[node][i]] == INF) {
                d2[G[node][i]] = d2[node] + 1;
                que.push(G[node][i]);
            }
        }
    }
    int shortest = d1[t];
    vector<int> r1(shortest - 1, 0);
    for (const auto &nodeDist : d1) {
        if (nodeDist < shortest - 1) {
            r1[nodeDist]++;
        }
    }
    vector<int> r2(shortest - 1, 0);
    for (const auto &nodeDist : d2) {
        if (nodeDist < shortest - 1) {
            r2[nodeDist]++;
        }
    }
    long long ret = 0;
    for (int i = 0; i < shortest - 1; i++) {
        ret += 1LL * r1[i] * r2[shortest - i - 2];
    }
    printf("%lld\n", ret);
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 10416
final_rank: 2

code_snippet: #include <functional>
#include <iostream>
#include <queue>
#include <vector>
#pragma warning(disable : 4996)
#define INF (1 << 23)
using namespace std;
int main() {
  int N, M, s, t, u, v;
  scanf("%d", &N);
  scanf("%d", &M);
  scanf("%d", &s);
  s--;
  scanf("%d", &t);
  t--;
  vector<vector<int>> G(N);
  for (int i = 0; i < M; i++) {
    scanf("%d", &u);
    scanf("%d", &v);
    G[u - 1].push_back(v - 1);
    G[v - 1].push_back(u - 1);
  }
  vector<int> d1(N, INF);
  d1[s] = 0;
  vector<int> d2(N, INF);
  d2[t] = 0;
  queue<int> que;
  que.push(s);
  while (!que.empty()) {
    int node = que.front();
    que.pop();
    int size = G[node].size();
    for (int i = 0; i < size; ++i) {
      int &neighbor = G[node][i];
      if (d1[neighbor] == INF) {
        d1[neighbor] = d1[node] + 1;
        que.push(neighbor);
      }
    }
  }
  que.push(t);
  while (!que.empty()) {
    int node = que.front();
    que.pop();
    int size = G[node].size();
    for (int i = 0; i < size; ++i) {
      int &neighbor = G[node][i];
      if (d2[neighbor] == INF) {
        d2[neighbor] = d2[node] + 1;
        que.push(neighbor);
      }
    }
  }
  int shortest = d1[t];
  vector<int> r1(shortest - 1, 0), r2(shortest - 1, 0);
  for (int i = 0; i < N; ++i) {
    if (d1[i] < shortest - 1) {
      r1[d1[i]]++;
    }
    if (d2[i] < shortest - 1) {
      r2[d2[i]]++;
    }
  }
  long long ret = 0;
  for (int i = 0; i < shortest - 1; ++i) {
    ret += 1LL * r1[i] * r2[shortest - i - 2];
  }
  printf("%lld\n", ret);
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 10412
final_rank: 11

code_snippet: #include <functional>
#include <iostream>
#include <queue>
#include <vector>
#define INF (1 << 23)
using namespace std;

int main() {
  int N, M, s, t, u, v;
  scanf("%d", &N);
  scanf("%d", &M);
  scanf("%d", &s);
  s--;
  scanf("%d", &t);
  t--;
  vector<vector<int>> G(N);
  for (int i = 0; i < M; i++) {
    scanf("%d", &u);
    scanf("%d", &v);
    G[u - 1].push_back(v - 1);
    G[v - 1].push_back(u - 1);
  }
  vector<int> d1(N, INF);
  d1[s] = 0;
  vector<int> d2(N, INF);
  d2[t] = 0;
  queue<int> que;
  que.push(s);
  while (!que.empty()) {
    int node = que.front(); que.pop();
    int size = G[node].size(); // Cache size
    for (int i = 0; i < size; i++) {
      if (d1[G[node][i]] == INF) {
        d1[G[node][i]] = d1[node] + 1;
        que.push(G[node][i]);
      }
    }
  }
  que.push(t);
  while (!que.empty()) {
    int node = que.front(); que.pop();
    int size = G[node].size(); // Cache size
    for (int i = 0; i < size; i++) {
      if (d2[G[node][i]] == INF) {
        d2[G[node][i]] = d2[node] + 1;
        que.push(G[node][i]);
      }
    }
  }
  int shortest = d1[t];
  vector<int> r1, r2;
  for (int i = 0; i < N; i++) {
    if (d1[i] < shortest - 1) {
      while(d1[i] >= r1.size()) r1.push_back(0);
      r1[d1[i]]++;
    }
  }
  for (int i = 0; i < N; i++) {
    if (d2[i] < shortest - 1) {
      while(d2[i] >= r2.size()) r2.push_back(0);
      r2[d2[i]]++;
    }
  }
  long long ret = 0;
  for (int i = 0; i < shortest - 1; i++) {
    ret += 1LL * r1[i] * r2[shortest - i - 2];
  }
  printf("%lld\n", ret);
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 10448
final_rank: 6

code_snippet: #include <iostream>
#include <vector>
#include <queue>
#define INF (1 << 23)
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 

    int N, M, s, t, u, v;
    cin >> N >> M >> s >> t;
    s--; t--;
    vector<vector<int>> G(N);

    for (int i = 0; i < M; i++) {
        cin >> u >> v;
        G[u - 1].push_back(v - 1);
        G[v - 1].push_back(u - 1);
    }

    vector<int> d1(N, INF), d2(N, INF);
    d1[s] = d2[t] = 0;
    queue<int> que;
    que.push(s);
    que.push(t);
    bool turn = true; // to switch between s and t

    while (!que.empty()) {
        int node = que.front();
        que.pop();
        for (int i = 0; i < G[node].size(); i++) {
            if (turn && d1[G[node][i]] == INF) {
                d1[G[node][i]] = d1[node] + 1;
                que.push(G[node][i]);
            }
            if (!turn && d2[G[node][i]] == INF) {
                d2[G[node][i]] = d2[node] + 1;
                que.push(G[node][i]);
            }
        }
        turn = !turn;
    }

    int shortest = d1[t];
    vector<int> r1(shortest - 1, 0), r2(shortest - 1, 0);

    for (int i = 0; i < N; i++) {
        if (d1[i] < shortest - 1) r1[d1[i]]++;
        if (d2[i] < shortest - 1) r2[d2[i]]++;
    }

    long long ret = 0;
    for (int i = 0; i < shortest - 1; i++) {
        ret += 1LL * r1[i] * r2[shortest - i - 2];
    }

    cout << ret << '\n';
    return 0;
}
accuracy: 0.0821917808219178
time_ms: 10
memory_kb: 68500
final_rank: 19

code_snippet: #include <iostream>
#include <vector>
#define INF (1 << 23)

// Custom Queue Implementation
template <typename T, int SIZE>
class Queue {
private:
    T data[SIZE];
    int front, rear, count;

public:
    Queue() : front(0), rear(0), count(0) {}

    void push(T element) {
        if (count == SIZE) {
            // Queue is full, handle the overflow case
            return;
        }
        data[rear] = element;
        rear = (rear + 1) % SIZE;
        count++;
    }

    T pop() {
        if (count == 0) {
            // Queue is empty, handle the underflow case
            return T();
        }
        T frontElement = data[front];
        front = (front + 1) % SIZE;
        count--;
        return frontElement;
    }

    bool empty() const {
        return count == 0;
    }
};

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int N, M, s, t, u, v;
    std::cin >> N >> M >> s >> t;
    s--;
    t--;

    std::vector<std::vector<int>> G(N);
    for (int i = 0; i < M; i++) {
        std::cin >> u >> v;
        G[u - 1].push_back(v - 1);
        G[v - 1].push_back(u - 1);
    }

    std::vector<int> d1(N, INF);
    d1[s] = 0;
    std::vector<int> d2(N, INF);
    d2[t] = 0;

    Queue<int, 10000> que;  // Custom queue with fixed size
    que.push(s);
    while (!que.empty()) {
        int node = que.pop();
        for (int i = 0; i < G[node].size(); i++) {
            int neighbor = G[node][i];
            if (d1[neighbor] == INF) {
                d1[neighbor] = d1[node] + 1;
                que.push(neighbor);
            }
        }
    }

    que.push(t);
    while (!que.empty()) {
        int node = que.pop();
        for (int i = 0; i < G[node].size(); i++) {
            int neighbor = G[node][i];
            if (d2[neighbor] == INF) {
                d2[neighbor] = d2[node] + 1;
                que.push(neighbor);
            }
        }
    }

    int shortest = d1[t];
    std::vector<int> r1(shortest - 1, 0);
    for (int i = 0; i < N; i++) {
        if (d1[i] < shortest - 1) {
            r1[d1[i]]++;
        }
    }

    std::vector<int> r2(shortest - 1, 0);
    for (int i = 0; i < N; i++) {
        if (d2[i] < shortest - 1) {
            r2[d2[i]]++;
        }
    }

    long long ret = 0;
    for (int i = 0; i < shortest - 1; i++) {
        ret += 1LL * r1[i] * r2[shortest - i - 2];
    }

    std::cout << ret << "\n";
    return 0;
}
accuracy: 0.726027397260274
time_ms: 20
memory_kb: 6964
final_rank: 18

code_snippet: #include <cstdio>
#include <vector>
#include <queue>
#include <list>
#pragma warning(disable : 4996)
#define INF (1 << 23)
using namespace std;

int main() {
  int N, M, s, t, u, v;
  scanf("%d", &N);
  scanf("%d", &M);
  scanf("%d", &s);
  s--;
  scanf("%d", &t);
  t--;

  vector<list<int>> G(N); // Use adjacency list instead of vector of vectors

  for (int i = 0; i < M; i++) {
    scanf("%d", &u);
    scanf("%d", &v);
    G[u - 1].push_back(v - 1);
    G[v - 1].push_back(u - 1);
  }

  vector<int> d1(N, INF);
  vector<int> d2(N, INF);
  d1[s] = 0;
  d2[t] = 0;

  queue<int> que;
  que.push(s);

  while (!que.empty()) {
    int node = que.front();
    que.pop();

    for (int neighbor : G[node]) { // Use range-based for loop for neighbors
      if (d1[neighbor] == INF) {
        d1[neighbor] = d1[node] + 1;
        que.push(neighbor);
      }
    }
  }

  que.push(t);

  while (!que.empty()) {
    int node = que.front();
    que.pop();

    for (int neighbor : G[node]) { // Use range-based for loop for neighbors
      if (d2[neighbor] == INF) {
        d2[neighbor] = d2[node] + 1;
        que.push(neighbor);
      }
    }
  }

  int shortest = d1[t];

  vector<int> r1(shortest - 1, 0); // Resize r1 and r2 upfront
  vector<int> r2(shortest - 1, 0);

  for (int i = 0; i < N; i++) {
    if (d1[i] < shortest - 1) {
      r1[d1[i]]++;
    }
  }

  for (int i = 0; i < N; i++) {
    if (d2[i] < shortest - 1) {
      r2[d2[i]]++;
    }
  }

  long long ret = 0;

  for (int i = 0; i < shortest - 1; i++) {
    ret += 1LL * r1[i] * r2[shortest - i - 2];
  }

  printf("%lld\n", ret);

  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 18492
final_rank: 13

code_snippet: #include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define INF (1 << 23)
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int N, M, s, t, u, v;
    cin >> N >> M >> s >> t;
    s--; t--;
    vector<vector<int>> G(N);
    G.reserve(N);
    for (int i = 0; i < M; i++) {
        cin >> u >> v;
        G[u - 1].emplace_back(v - 1);
        G[v - 1].emplace_back(u - 1);
    }
    vector<int> d1(N, INF);
    vector<int> d2(N, INF);
    d1[s] = d2[t] = 0;
    queue<int> que;
    que.push(s);
    while (!que.empty()) {
        int node = que.front(); que.pop();
        for (auto& i : G[node]) {
            if (d1[i] == INF) {
                d1[i] = d1[node] + 1;
                que.push(i);
            }
        }
    }
    que.push(t);
    while (!que.empty()) {
        int node = que.front(); que.pop();
        for (auto& i : G[node]) {
            if (d2[i] == INF) {
                d2[i] = d2[node] + 1;
                que.push(i);
            }
        }
    }
    int shortest = d1[t];
    vector<int> r1(shortest - 1, 0), r2(shortest - 1, 0);
    for (int i = 0; i < N; i++) {
        if (d1[i] < shortest - 1) r1[d1[i]]++;
        if (d2[i] < shortest - 1) r2[d2[i]]++;
    }
    long long ret = 0;
    for (int i = 0; i < shortest - 1; i++) {
        ret += 1LL * r1[i] * r2[shortest - i - 2];
    }
    cout << ret << "\n";
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 10440
final_rank: 4

code_snippet: #include <functional>
#include <iostream>
#include <queue>
#include <vector>
#pragma warning(disable : 4996)
#define INF (1 << 23)
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  int N, M, s, t, u, v;
  scanf("%d%d%d%d", &N, &M, &s, &t);
  s--;
  t--;
  vector<vector<int>> G(N);
  for (int i = 0; i < M; i++) {
    scanf("%d%d", &u, &v);
    G[u - 1].push_back(v - 1);
    G[v - 1].push_back(u - 1);
  }
  vector<int> d1(N, INF);
  d1[s] = 0;
  vector<int> d2(N, INF);
  d2[t] = 0;
  queue<int> que;
  que.push(s);
  while (!que.empty()) {
    int node = que.front();
    que.pop();
    for (int i = 0; i < G[node].size(); i++) {
      if (d1[G[node][i]] == INF) {
        d1[G[node][i]] = d1[node] + 1;
        que.push(G[node][i]);
      }
    }
  }
  que.push(t);
  while (!que.empty()) {
    int node = que.front();
    que.pop();
    for (int i = 0; i < G[node].size(); i++) {
      if (d2[G[node][i]] == INF) {
        d2[G[node][i]] = d2[node] + 1;
        que.push(G[node][i]);
      }
    }
  }
  int shortest = d1[t];
  vector<int> r1(shortest - 1, 0);
  for (int i = 0; i < N; i++) {
    if (d1[i] < shortest - 1) {
      r1[d1[i]]++;
    }
  }
  vector<int> r2(shortest - 1, 0);
  for (int i = 0; i < N; i++) {
    if (d2[i] < shortest - 1) {
      r2[d2[i]]++;
    }
  }
  long long ret = 0;
  for (int i = 0; i < shortest - 1; i++) {
    ret += 1LL * r1[i] * r2[shortest - i - 2];
  }
  printf("%lld\n", ret);
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 10500
final_rank: 8

code_snippet: #include <functional>
#include <iostream>
#include <queue>
#include <vector>
#pragma warning(disable : 4996)
#define INF (1 << 23)
using namespace std;
int main() {
  int N, M, s, t, u, v;
  scanf("%d %d %d %d", &N, &M, &s, &t);
  s--;
  t--;
  vector<vector<int>> G(N);
  for (int i = 0; i < M; i++) {
    scanf("%d %d", &u, &v);
    G[u - 1].push_back(v - 1);
  }
  vector<int> d1(N, INF);
  d1[s] = 0;
  vector<int> d2(N, INF);
  d2[t] = 0;
  queue<int> que;
  que.push(s);
  while (!que.empty()) {
    int node = que.front();
    que.pop();
    int size = G[node].size();
    for (int i = 0; i < size; i++) {
      int neighbour = G[node][i];
      if (d1[neighbour] == INF) {
        d1[neighbour] = d1[node] + 1;
        que.push(neighbour);
      }
    }
  }
  que.push(t);
  while (!que.empty()) {
    int node = que.front();
    que.pop();
    int size = G[node].size();
    for (int i = 0; i < size; i++) {
      int neighbour = G[node][i];
      if (d2[neighbour] == INF) {
        d2[neighbour] = d2[node] + 1;
        que.push(neighbour);
      }
    }
  }
  int shortest = d1[t];
  vector<int> r1(shortest, 0);
  vector<int> r2(shortest, 0);
  r1[shortest - 1] = 1;
  r2[shortest - 1] = 1;
  for (int i = 0; i < N; i++) {
    if (d1[i] < shortest - 1) {
      r1[d1[i]]++;
    }
    if (d2[i] < shortest - 1) {
      r2[d2[i]]++;
    }
  }
  long long ret = 0;
  for (int i = 0; i < shortest - 1; i++) {
    ret += r1[i] * r2[shortest - i - 2];
  }
  cout << ret << '\n';
  return 0;
}
accuracy: 0.0273972602739726
time_ms: 10
memory_kb: 68612
final_rank: 20

code_snippet: #include <functional>
#include <iostream>
#include <queue>
#include <vector>

#define INF (1 << 23)
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int N, M, s, t, u, v;
  scanf("%d", &N);
  scanf("%d", &M);
  scanf("%d", &s);
  s--;
  scanf("%d", &t);
  t--;

  vector<vector<int>> G(N);
  G.reserve(N);

  for (int i = 0; i < M; i++) {
    scanf("%d", &u);
    scanf("%d", &v);
    G[u - 1].emplace_back(v - 1);
    G[v - 1].emplace_back(u - 1);
  }

  vector<int> d1(N, INF);
  d1[s] = 0;
  vector<int> d2(N, INF);
  d2[t] = 0;
  
  queue<int> que;
  que.push(s);
  
  while (!que.empty()) {
    int node = que.front();
    que.pop();
    for (int i = 0; i < G[node].size(); i++) {
      if (d1[G[node][i]] == INF) {
        d1[G[node][i]] = d1[node] + 1;
        que.push(G[node][i]);
      }
    }
  }
  que.push(t);
  while (!que.empty()) {
    int node = que.front();
    que.pop();
    for (int i = 0; i < G[node].size(); i++) {
      if (d2[G[node][i]] == INF) {
        d2[G[node][i]] = d2[node] + 1;
        que.push(G[node][i]);
      }
    }
  }
  int shortest = d1[t];
  vector<int> r1(shortest - 1, 0);
  vector<int> r2(shortest - 1, 0);
  
  for (int i = 0; i < N; i++) {
    if (d1[i] < shortest - 1) {
      r1[d1[i]]++;
    }
    if (d2[i] < shortest - 1) {
      r2[d2[i]]++;
    }
  }
  long long ret = 0;
  for (int i = 0; i < shortest - 1; i++) {
    ret += 1LL * r1[i] * r2[shortest - i - 2];
  }
  printf("%lld\n", ret);
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 10404
final_rank: 1

code_snippet: #include <functional>
#include <iostream>
#include <queue>
#include <vector>
#define INF (1 << 23)

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  int N, M, s, t;
  std::cin >> N >> M >> s >> t;
  s--;
  t--;
  std::vector<std::vector<int>> G(N);
  G.reserve(N);
  for (int i = 0; i < M; i++) {
    int u, v;
    std::cin >> u >> v;
    G[u - 1].push_back(v - 1);
    G[v - 1].push_back(u - 1);
  }
  std::vector<int> d1(N, INF);
  d1[s] = 0;
  std::vector<int> d2(N, INF);
  d2[t] = 0;
  std::queue<int> que;
  que.push(s);
  while (!que.empty()) {
    int node = que.front();
    que.pop();
    for (auto neighbour : G[node]) {
      if (d1[neighbour] == INF) {
        d1[neighbour] = d1[node] + 1;
        que.push(neighbour);
      }
    }
  }
  que.push(t);
  while (!que.empty()) {
    int node = que.front();
    que.pop();
    for (auto neighbour : G[node]) {
      if (d2[neighbour] == INF) {
        d2[neighbour] = d2[node] + 1;
        que.push(neighbour);
      }
    }
  }
  int shortest = d1[t];
  std::vector<int> r1(shortest - 1, 0);
  for (int i = 0; i < N; i++) {
    if (d1[i] < shortest - 1) {
      r1[d1[i]]++;
    }
  }
  std::vector<int> r2(shortest - 1, 0);
  for (int i = 0; i < N; i++) {
    if (d2[i] < shortest - 1) {
      r2[d2[i]]++;
    }
  }
  long long ret = 0;
  for (int i = 0; i < shortest - 1; i++) {
    ret += 1LL * r1[i] * r2[shortest - i - 2];
  }
  std::cout << ret << "\n";
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 10436
final_rank: 3

code_snippet: #include <functional>
#include <iostream>
#include <queue>
#include <vector>
#pragma warning(disable : 4996)
#define INF (1 << 23)
using namespace std;
int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int N, M, s, t, u, v;
  scanf("%d", &N);
  scanf("%d", &M);
  scanf("%d", &s);
  s--;
  scanf("%d", &t);
  t--;
  vector<vector<int>> G(N);
  G.reserve(N);
  for (int i = 0; i < M; ++i) {
    scanf("%d", &u);
    scanf("%d", &v);
    G[u - 1].emplace_back(v - 1);
    G[v - 1].emplace_back(u - 1);
  }
  vector<int> d1(N, INF);
  d1[s] = 0;
  vector<int> d2(N, INF);
  d2[t] = 0;
  queue<int> que;
  que.push(s);
  while (!que.empty()) {
    int node = que.front();
    que.pop();
    for (auto& i : G[node]) {
      if (d1[i] == INF) {
        d1[i] = d1[node] + 1;
        que.push(i);
      }
    }
  }
  que.push(t);
  while (!que.empty()) {
    int node = que.front();
    que.pop();
    for (auto& i : G[node]) {
      if (d2[i] == INF) {
        d2[i] = d2[node] + 1;
        que.push(i);
      }
    }
  }
  int shortest = d1[t];
  vector<int> r1(shortest - 1, 0);
  vector<int> r2(shortest - 1, 0);
  for (int i = 0; i < N; ++i) {
    if (d1[i] < shortest - 1) {
      r1[d1[i]]++;
    }
    if (d2[i] < shortest - 1) {
      r2[d2[i]]++;
    }
  }
  long long ret = 0;
  for (int i = 0; i < shortest - 1; ++i) {
    ret += 1LL * r1[i] * r2[shortest - i - 2];
  }
  printf("%lld\n", ret);
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 10472
final_rank: 7