153852025-02-19 10:25:09AblablablaAutópálya inflációcpp17Wrong answer 15/100108ms71656 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<ll, ll> pii;

const ll INF = 4e18 + 7;
const ll MOD = 1e9 + 7;

vector<ll> ans;
vector<ll> mely;

struct comp{
    bool operator()(ll a, ll b){
        if(ans[a] == ans[b]){
            return mely[a] > mely[b];
        }
        return ans[a] > ans[b];
    }
};

int main()
{
    ll n, m;
    cin >> n >> m;

    vector<vector<ll>> csucsok(n, vector<ll>()), hossz(n, vector<ll>());
    for(ll i = 0; i < m; i++){
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;

        csucsok[a].push_back(b);
        hossz[a].push_back(c);
        csucsok[b].push_back(a);
        hossz[b].push_back(c);
    }

    priority_queue<ll, vector<ll>, comp> bejar;
    ans.assign(n, INF);
    ans[0] = 0;
    bejar.push(0);
    vector<bool> bejart(n);
    vector<vector<ll>> opciok(n, vector<ll>(n + 2, INF));
    opciok[0][1] = 0;
    mely.assign(n, 0);


    while(!bejar.empty()){
        ll akt = bejar.top();
        bejar.pop();

        if(bejart[akt]) continue;

        bejart[akt] = 1;

        for(ll i = 0; i < csucsok[akt].size(); i++){
            ll kovi = csucsok[akt][i];
            ll suly = hossz[akt][i];

            if(bejart[kovi]) continue;

            for(int i = 1; i <= n; i++){
                if(opciok[akt][i] == INF) continue;

                ll tav = (opciok[akt][i] + suly*(1ll << (i - 1)));
                opciok[kovi][i + 1] = min(opciok[kovi][i + 1], tav);

                if(ans[kovi] > tav) mely[kovi] = i + 1;
                ans[kovi] = min(ans[kovi], tav);
            }

            bejar.push(kovi);
        }
    }

    for(int i = 1; i < n; i++){
        cout << ans[i] % MOD << "\n";
    }

    /*for(int j = 1; j <= n; j++){
        for(int i = 0; i < n; i++){
            if(opciok[i][j] == INF){
                cout << "-1\t";
            } else{
                cout << opciok[i][j] << "\t";
            }
        }
        cout << "\n";
    }*/
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Wrong answer92ms71476 KiB
subtask20/8
3Accepted75ms71220 KiB
4Wrong answer86ms71220 KiB
5Wrong answer74ms71368 KiB
6Accepted86ms71476 KiB
7Wrong answer74ms71224 KiB
subtask315/15
8Accepted1ms508 KiB
9Accepted1ms508 KiB
10Accepted1ms316 KiB
11Accepted1ms508 KiB
12Accepted1ms316 KiB
13Accepted1ms316 KiB
14Accepted1ms316 KiB
15Accepted1ms316 KiB
16Accepted1ms316 KiB
17Accepted1ms316 KiB
18Accepted1ms316 KiB
subtask40/34
19Accepted92ms71512 KiB
20Wrong answer103ms71656 KiB
21Wrong answer103ms71652 KiB
22Accepted92ms71564 KiB
23Accepted104ms71484 KiB
24Wrong answer104ms71420 KiB
25Accepted92ms71652 KiB
26Accepted90ms71444 KiB
27Wrong answer89ms71328 KiB
28Wrong answer72ms71124 KiB
29Wrong answer86ms71028 KiB
30Wrong answer74ms62260 KiB
31Wrong answer71ms70708 KiB
32Wrong answer87ms71036 KiB
33Wrong answer100ms70968 KiB
subtask50/21
34Wrong answer4ms2360 KiB
35Wrong answer7ms2356 KiB
36Wrong answer7ms2356 KiB
37Wrong answer7ms2580 KiB
38Accepted7ms2572 KiB
39Accepted7ms2448 KiB
40Wrong answer7ms2356 KiB
41Wrong answer7ms2336 KiB
42Wrong answer4ms2360 KiB
43Wrong answer3ms2356 KiB
44Wrong answer4ms2356 KiB
45Wrong answer3ms2356 KiB
46Wrong answer4ms2356 KiB
47Wrong answer3ms2188 KiB
48Wrong answer4ms2356 KiB
49Wrong answer4ms2356 KiB
subtask60/22
50Wrong answer90ms71476 KiB
51Wrong answer105ms71548 KiB
52Wrong answer104ms71516 KiB
53Wrong answer93ms71476 KiB
54Accepted92ms71484 KiB
55Accepted104ms71572 KiB
56Wrong answer96ms71476 KiB
57Wrong answer108ms71416 KiB
58Wrong answer9ms8256 KiB
59Wrong answer74ms71040 KiB
60Wrong answer86ms71220 KiB
61Wrong answer86ms71276 KiB
62Wrong answer71ms69700 KiB
63Wrong answer72ms70248 KiB
64Wrong answer90ms70908 KiB
65Wrong answer103ms70836 KiB
66Wrong answer101ms71256 KiB