250942026-02-17 21:26:04KevinBarátnők (50 pont)cpp17Wrong answer 2/501.09s5068 KiB
#include <bits/stdc++.h>
#include <queue>
using namespace std;
using ll=long long;
using pll=pair<ll, ll>;
const ll MOD=1e9+7;

ll a, b;
vector<vector<pll>> vec;
priority_queue<pll, vector<pll>, greater<pll>> pq;
vector<ll> dis;
set<pll> s;

/*
ll fastPow(ll a, ll b){
    if (b==0) return 1;
    if (a==1) return 1;
    if (b%2==0) return fastPow(a*a%MOD, b/2);
    else return fastPow(a, b-1)*a%MOD;
}
*/

void dfs(ll x, pll tala){
    for (auto& z:vec[x]){
        if (dis[z.first]==dis[x]+z.second){
            if (z.first==b){
                s.insert(tala);
                //cerr << tala.first << ' ' << tala.second << '\n';
                return;
            }
            if (dis[b]%2==0 && dis[b]/2==dis[z.first]) tala={z.first, z.first};
            else if (dis[x]<(dis[b]+1)/2 && (dis[b]-1)/2<=dis[z.first]) tala={x, z.first};
            dfs(z.first, tala);
        }
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n, m; cin >> n >> m;
    vec.resize(n);
    dis.resize(n, INT_MAX);
    for (ll i=0; i<n; i++){
        ll a, b, c; cin >> a >> b >> c;
        vec[a-1].push_back({b-1, c});
        vec[b-1].push_back({a-1, c});
    }
    cin >> a >> b; a--; b--;
    dis[a]=0;
    pq.push({0, a});
    while (pq.size()>0){
        pll x=pq.top();
        pq.pop();
        if (dis[x.second]==x.first){
            for (auto& z:vec[x.second]){
                if (dis[z.first]>dis[x.second]+z.second){
                    dis[z.first]=dis[x.second]+z.second;
                    pq.push({dis[z.first], z.first});
                }
            }
        }
    }
    dfs(a, {-1, -1});
    cout << s.size()%MOD*(s.size()-1)%MOD;
}
SubtaskSumTestVerdictTimeMemory
base2/50
1Accepted0/01ms508 KiB
2Wrong answer0/029ms4404 KiB
3Wrong answer0/21ms316 KiB
4Wrong answer0/21ms316 KiB
5Wrong answer0/21ms316 KiB
6Wrong answer0/21ms316 KiB
7Wrong answer0/21ms316 KiB
8Runtime error0/126ms4596 KiB
9Time limit exceeded0/21.085s5068 KiB
10Wrong answer0/257ms4728 KiB
11Wrong answer0/227ms4404 KiB
12Time limit exceeded0/21.09s4852 KiB
13Wrong answer0/2172ms4404 KiB
14Wrong answer0/227ms4404 KiB
15Wrong answer0/226ms4404 KiB
16Accepted1/139ms4652 KiB
17Accepted1/143ms4660 KiB
18Runtime error0/127ms4680 KiB
19Wrong answer0/228ms4532 KiB
20Wrong answer0/243ms4916 KiB
21Wrong answer0/243ms4660 KiB
22Wrong answer0/226ms3636 KiB
23Wrong answer0/229ms4588 KiB
24Wrong answer0/228ms3636 KiB
25Wrong answer0/217ms2100 KiB
26Wrong answer0/237ms4660 KiB
27Wrong answer0/246ms4788 KiB
28Wrong answer0/237ms4744 KiB
29Wrong answer0/239ms3860 KiB