153432025-02-19 07:55:53AblablablaAutópálya inflációcpp17Wrong answer 0/100111ms71636 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;

        //cout << akt << "\n";

        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*i);
                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 answer93ms71476 KiB
subtask20/8
3Wrong answer87ms71220 KiB
4Wrong answer87ms71232 KiB
5Wrong answer75ms71220 KiB
6Wrong answer86ms71476 KiB
7Wrong answer74ms71208 KiB
subtask30/15
8Wrong answer1ms316 KiB
9Wrong answer1ms316 KiB
10Wrong answer1ms500 KiB
11Wrong answer1ms500 KiB
12Wrong answer1ms316 KiB
13Wrong answer1ms500 KiB
14Accepted1ms316 KiB
15Wrong answer1ms316 KiB
16Accepted1ms316 KiB
17Wrong answer1ms316 KiB
18Wrong answer1ms316 KiB
subtask40/34
19Wrong answer105ms71636 KiB
20Wrong answer92ms71600 KiB
21Wrong answer104ms71476 KiB
22Wrong answer92ms71448 KiB
23Wrong answer104ms71468 KiB
24Wrong answer104ms71540 KiB
25Wrong answer90ms71632 KiB
26Wrong answer90ms71524 KiB
27Wrong answer108ms71476 KiB
28Wrong answer74ms70968 KiB
29Wrong answer72ms71220 KiB
30Wrong answer78ms62168 KiB
31Wrong answer71ms70936 KiB
32Wrong answer89ms70968 KiB
33Wrong answer98ms70964 KiB
subtask50/21
34Wrong answer4ms2548 KiB
35Wrong answer7ms2356 KiB
36Wrong answer7ms2356 KiB
37Wrong answer7ms2548 KiB
38Wrong answer7ms2356 KiB
39Wrong answer7ms2540 KiB
40Wrong answer7ms2356 KiB
41Wrong answer7ms2356 KiB
42Wrong answer4ms2360 KiB
43Wrong answer4ms2364 KiB
44Wrong answer4ms2356 KiB
45Wrong answer4ms2356 KiB
46Wrong answer4ms2356 KiB
47Wrong answer3ms2100 KiB
48Wrong answer4ms2356 KiB
49Wrong answer4ms2356 KiB
subtask60/22
50Wrong answer107ms71464 KiB
51Wrong answer105ms71444 KiB
52Wrong answer92ms71480 KiB
53Wrong answer93ms71600 KiB
54Wrong answer104ms71472 KiB
55Wrong answer92ms71544 KiB
56Wrong answer98ms71476 KiB
57Wrong answer111ms71316 KiB
58Wrong answer9ms8244 KiB
59Wrong answer74ms71208 KiB
60Wrong answer86ms71220 KiB
61Wrong answer86ms71220 KiB
62Wrong answer72ms69828 KiB
63Wrong answer71ms70196 KiB
64Wrong answer103ms70964 KiB
65Wrong answer92ms70892 KiB
66Wrong answer105ms71356 KiB