160792025-03-30 19:59:22szilAutópálya inflációcpp17Time limit exceeded 36/1002.099s6284 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

const int BLOCK_CNT = 55;
const int BLOCK_SIZE = 60;

const ll MULTI = (1ll<<(1+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] &= ~(1ull << (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] &= ~(1ull << 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--) {
            data[i] %= MOD;
            ans += data[i] * mul;
            ans %= MOD;
            mul *= MULTI;
            mul %= MOD;
        }
        return ans;
    }
};

int u[MAXM], v[MAXM];
bool vis[MAXN];

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();
        // ll x;
        // cin >> u[i] >> v[i] >> x;
        // for (int j = BLOCK_CNT-1; j >= 0; j--) {
        //     w[i].data[j] = x & ((1ll<<(1+BLOCK_SIZE))-1);
        //     x >>= (1 + BLOCK_SIZE);
        // }
    }
    vector<bigint> dist_last(n+1);
    dist_last[1].clear();
    vis[1] = 1;
    for (int i = 1; i <= n; i++) {
        vector<bigint> dist_curr = dist_last;
        for (int j = 1; j <= m; j++) {
            if (vis[u[j]] && dist_last[u[j]] + w[j] < dist_curr[v[j]]) {
                dist_curr[v[j]] = dist_last[u[j]] + w[j];
                vis[v[j]] = 1;
            }
        }
        for (int j = 1; j <= m; j++) {
            if (vis[v[j]] && dist_last[v[j]] + w[j] < dist_curr[u[j]]) {
                dist_curr[u[j]] = dist_last[v[j]] + w[j];
                vis[u[j]] = 1;
            }
        }

        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
2Time limit exceeded2.092s6084 KiB
subtask20/8
3Time limit exceeded2.071s4804 KiB
4Time limit exceeded2.071s4808 KiB
5Time limit exceeded2.071s4612 KiB
6Time limit exceeded2.071s4608 KiB
7Time limit exceeded2.076s4804 KiB
subtask315/15
8Accepted1ms316 KiB
9Accepted1ms316 KiB
10Accepted1ms316 KiB
11Accepted1ms508 KiB
12Accepted1ms316 KiB
13Accepted1ms316 KiB
14Accepted1ms316 KiB
15Accepted1ms316 KiB
16Accepted1ms316 KiB
17Accepted1ms316 KiB
18Accepted1ms316 KiB
subtask40/34
19Time limit exceeded2.099s5984 KiB
20Time limit exceeded2.098s6040 KiB
21Time limit exceeded2.099s6028 KiB
22Time limit exceeded2.099s5956 KiB
23Time limit exceeded2.079s6024 KiB
24Time limit exceeded2.081s6036 KiB
25Time limit exceeded2.081s5964 KiB
26Time limit exceeded2.082s6036 KiB
27Time limit exceeded2.081s5940 KiB
28Time limit exceeded2.082s4608 KiB
29Time limit exceeded2.082s4604 KiB
30Time limit exceeded2.084s4176 KiB
31Time limit exceeded2.092s4604 KiB
32Time limit exceeded2.092s6008 KiB
33Time limit exceeded2.095s6012 KiB
subtask521/21
34Accepted342ms1364 KiB
35Accepted709ms1836 KiB
36Accepted712ms1844 KiB
37Accepted717ms1844 KiB
38Accepted714ms1844 KiB
39Accepted716ms1844 KiB
40Accepted708ms1844 KiB
41Accepted705ms1844 KiB
42Accepted187ms1076 KiB
43Accepted177ms1076 KiB
44Accepted179ms1076 KiB
45Accepted177ms1132 KiB
46Accepted186ms1140 KiB
47Accepted172ms1076 KiB
48Accepted342ms1332 KiB
49Accepted338ms1336 KiB
subtask60/22
50Time limit exceeded2.088s6164 KiB
51Time limit exceeded2.088s6284 KiB
52Time limit exceeded2.088s6028 KiB
53Time limit exceeded2.088s5960 KiB
54Time limit exceeded2.078s6028 KiB
55Time limit exceeded2.079s6044 KiB
56Time limit exceeded2.079s6004 KiB
57Time limit exceeded2.081s5940 KiB
58Accepted748ms1832 KiB
59Time limit exceeded2.089s4620 KiB
60Time limit exceeded2.089s4748 KiB
61Time limit exceeded2.092s4616 KiB
62Time limit exceeded2.078s4404 KiB
63Time limit exceeded2.078s4580 KiB
64Time limit exceeded2.081s6016 KiB
65Time limit exceeded2.082s6004 KiB
66Time limit exceeded2.089s5940 KiB