Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright © 2017 Adán López Alatorre. All rights reserved.
- //
- #include <iostream>
- #include <vector>
- #include <string.h>
- #include <deque>
- #include <queue>
- #include <algorithm>
- #include <set>
- #include <map>
- #include <sstream>
- #include <stack>
- #include <iomanip>
- #include <fstream>
- #include <climits>
- #include <cmath>
- #define fi first
- #define se second
- #define FI first.first
- #define SE first.second
- #define TH second
- #define MAXN maxN
- using namespace std;
- typedef long long ll;
- typedef pair<int, int> ii;
- typedef pair<ii, int> iii;
- typedef pair<double, int> di;
- typedef vector<int> vi;
- typedef set<ii>::iterator iter;
- const int maxN = 2e3 + 3, MOD = 1e9 + 7, AL = 10;
- int toh[maxN], frh[maxN];
- bool mat[maxN][maxN];
- vector<int> adj[maxN];
- void bfs(int s, int *arr){
- queue<ii> q;
- q.push(ii(s, 0));
- memset(arr, -1, sizeof(toh));
- arr[s] = 0;
- while(q.size()){
- ii cur = q.front(); q.pop();
- for(int sn: adj[cur.fi])
- if(arr[sn] == -1)
- arr[sn] = cur.se + 1, q.push(ii(sn, cur.se + 1));
- }
- }
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(0), cout.tie(0);
- int n, m, s, t;
- cin >> n >> m >> s >> t;
- s--, t--;
- for(int i = 0, u, v; i < m; i++){
- cin >> u >> v;
- u--, v--;
- adj[u].push_back(v), adj[v].push_back(u);
- mat[u][v] = mat[v][u] = true;
- }
- bfs(s, toh), bfs(t, frh);
- int res = 0;
- for(int i = 0; i < n; i++){
- for(int j = i + 1; j < n; j++){
- if(mat[i][j]) continue;
- int bes = min(toh[i] + frh[j] + 1, toh[j] + frh[i] + 1);
- if(bes >= toh[t]) res++;
- }
- }
- cout << res << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement