250932026-02-17 21:20:59KevinBarátnők (50 pont)cpp17Wrong answer 0/501.1s5948 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 << fastPow(2, s.size());
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/01ms500 KiB
2Wrong answer0/029ms5424 KiB
3Wrong answer0/21ms316 KiB
4Wrong answer0/21ms508 KiB
5Wrong answer0/21ms316 KiB
6Wrong answer0/21ms316 KiB
7Wrong answer0/21ms316 KiB
8Runtime error0/128ms5192 KiB
9Time limit exceeded0/21.1s5876 KiB
10Wrong answer0/254ms5512 KiB
11Wrong answer0/228ms5480 KiB
12Time limit exceeded0/21.083s5544 KiB
13Wrong answer0/2179ms5360 KiB
14Wrong answer0/230ms5420 KiB
15Wrong answer0/229ms5436 KiB
16Wrong answer0/139ms5684 KiB
17Wrong answer0/148ms5948 KiB
18Runtime error0/128ms5428 KiB
19Wrong answer0/228ms5744 KiB
20Wrong answer0/250ms5940 KiB
21Wrong answer0/250ms5940 KiB
22Wrong answer0/227ms4724 KiB
23Wrong answer0/232ms5740 KiB
24Wrong answer0/229ms4492 KiB
25Wrong answer0/217ms2868 KiB
26Wrong answer0/239ms5940 KiB
27Wrong answer0/248ms5748 KiB
28Wrong answer0/241ms5940 KiB
29Wrong answer0/241ms4660 KiB