160702025-03-30 19:09:45szilAutópálya inflációcpp17Runtime error 15/1002.099s4444 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll MOD = 1e9+7;
const int MAXM = 3001;

const int BLOCK_CNT = 50;
const int BLOCK_SIZE = 62;

const ll MULTI = (1ll<<BLOCK_SIZE)%MOD;

struct bigint {

    vector<uint64_t> data;

    bigint() {
        data.assign(BLOCK_CNT, ~0ull);
    }

    void clear() {
        data.assign(BLOCK_CNT, 0ull);
    }

    bool operator<(const bigint &rhs) {
        for (int i = 0; i < BLOCK_CNT; i++) {
            if (data[i] != rhs.data[i]) {
                return data[i] < rhs.data[i];
            }
        }
        return 0;
    }

    bigint operator+(const bigint &rhs) {
        bigint res;
        res.clear();
        bool carry = 0;
        for (int i = BLOCK_CNT-1; i >= 0; i--) {
            res.data[i] = data[i] + rhs.data[i] + carry;
            carry = (res.data[i] >> (BLOCK_SIZE + 1)) & 1;
            res.data[i] &= ~(1ll << (BLOCK_SIZE + 1));
        }

        return res;
    }

    void inflate() {
        bool carry = 0;
        for (int i = BLOCK_CNT-1; i >= 0; i--) {
            bool next_carry = (data[i] >> BLOCK_SIZE) & 1;
            data[i] &= ~(1ll << BLOCK_SIZE);
            data[i] <<= 1;
            data[i] |= carry;
            carry = next_carry;
        }
    }

    ll calc_ans() {
        ll ans = 0;
        ll mul = 1;
        for (int i = BLOCK_CNT-1; i >= 0; i--) {
            ans += data[i];
            ans %= MOD;
            mul *= MULTI;
            mul %= MOD;
        }
        return ans;
    }
};

int u[MAXM], v[MAXM];

void solve() {
    int n, m; cin >> n >> m;
    vector<bigint> w(m+1);
    for (int i = 1; i <= m; i++) {
        w[i].clear();
        cin >> u[i] >> v[i] >> w[i].data.back();
    }
    vector<bigint> dist_last(n+1);
    dist_last[1].clear();
    for (int i = 1; i <= n; i++) {
        vector<bigint> dist_curr = dist_last;
        for (int j = 1; j <= m; j++) {
            if (dist_last[u[j]] + w[j] < dist_curr[v[j]]) {
                dist_curr[v[j]] = dist_last[u[j]] + w[j];
            }
        }
        for (int j = 1; j <= m; j++) {
            if (dist_last[v[j]] + w[j] < dist_curr[u[j]]) {
                dist_curr[u[j]] = dist_last[v[j]] + w[j];
            }
        }

        dist_last = dist_curr;

        for (int j = 1; j <= m; j++) {
            w[j].inflate();
        }
    }

    for (int i = 2; i <= n; i++) {
        cout << dist_last[i].calc_ans() << "\n";
    }
    cout << "\n";
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t = 1; 
    // cin >> t;
    while (t--) solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Runtime error4ms2880 KiB
subtask20/8
3Time limit exceeded2.075s4316 KiB
4Time limit exceeded2.075s4320 KiB
5Time limit exceeded2.075s4316 KiB
6Time limit exceeded2.075s4340 KiB
7Time limit exceeded2.079s4312 KiB
subtask315/15
8Accepted1ms508 KiB
9Accepted1ms316 KiB
10Accepted1ms508 KiB
11Accepted1ms316 KiB
12Accepted1ms316 KiB
13Accepted1ms316 KiB
14Accepted1ms500 KiB
15Accepted1ms316 KiB
16Accepted1ms316 KiB
17Accepted1ms316 KiB
18Accepted1ms316 KiB
subtask40/34
19Runtime error4ms3048 KiB
20Runtime error4ms3076 KiB
21Runtime error4ms3012 KiB
22Runtime error4ms3024 KiB
23Runtime error4ms3060 KiB
24Runtime error4ms3032 KiB
25Runtime error4ms2868 KiB
26Runtime error4ms2868 KiB
27Runtime error4ms2868 KiB
28Time limit exceeded2.078s4148 KiB
29Time limit exceeded2.099s4320 KiB
30Time limit exceeded2.099s3892 KiB
31Time limit exceeded2.085s4304 KiB
32Runtime error4ms2868 KiB
33Runtime error4ms2868 KiB
subtask50/21
34Wrong answer273ms1076 KiB
35Accepted529ms1588 KiB
36Accepted531ms1588 KiB
37Accepted529ms1736 KiB
38Accepted527ms1772 KiB
39Accepted527ms1736 KiB
40Wrong answer518ms1588 KiB
41Wrong answer518ms1588 KiB
42Wrong answer145ms1076 KiB
43Wrong answer148ms1072 KiB
44Wrong answer149ms1076 KiB
45Wrong answer149ms1076 KiB
46Wrong answer149ms1072 KiB
47Wrong answer137ms820 KiB
48Wrong answer264ms1076 KiB
49Wrong answer263ms1260 KiB
subtask60/22
50Runtime error4ms2868 KiB
51Runtime error4ms2868 KiB
52Runtime error4ms3060 KiB
53Runtime error4ms2868 KiB
54Runtime error4ms3100 KiB
55Runtime error4ms3196 KiB
56Runtime error4ms2992 KiB
57Runtime error4ms2868 KiB
58Wrong answer639ms1728 KiB
59Time limit exceeded2.088s4340 KiB
60Time limit exceeded2.099s4316 KiB
61Time limit exceeded2.099s4316 KiB
62Time limit exceeded2.085s4444 KiB
63Time limit exceeded2.082s4288 KiB
64Runtime error4ms2868 KiB
65Runtime error4ms2868 KiB
66Runtime error4ms2868 KiB