160832025-03-30 20:12:30szilAutópálya inflációcpp17Time limit exceeded 36/1002.099s6032 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];

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);
    vector<bool> vis_last(n+1);
    dist_last[1].clear();
    vis_last[1] = 1;
    int is_ok = -1;
    for (int i = 1; i <= n; i++) {

        if (is_ok != -1 && is_ok + 40 < i) break;

        bool ok = true;
        for (int j = 1; j <= n; j++) {
            if (!vis_last[j]) ok = false;
        }
        if (ok && is_ok == -1) {
            is_ok = i;
        }

        vector<bigint> dist_curr = dist_last;
        vector<bool> vis_curr = vis_last;
        for (int j = 1; j <= m; j++) {
            if (vis_last[u[j]] && dist_last[u[j]] + w[j] < dist_curr[v[j]]) {
                dist_curr[v[j]] = dist_last[u[j]] + w[j];
                vis_curr[v[j]] = 1;
            }
        }
        for (int j = 1; j <= m; j++) {
            if (vis_last[v[j]] && dist_last[v[j]] + w[j] < dist_curr[u[j]]) {
                dist_curr[u[j]] = dist_last[v[j]] + w[j];
                vis_curr[u[j]] = 1;
            }
        }

        dist_last = dist_curr;
        vis_last = vis_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
1Accepted1ms508 KiB
2Accepted316ms5940 KiB
subtask20/8
3Accepted163ms4624 KiB
4Accepted246ms4604 KiB
5Accepted287ms4404 KiB
6Accepted131ms4596 KiB
7Time limit exceeded2.082s4416 KiB
subtask315/15
8Accepted1ms316 KiB
9Accepted1ms508 KiB
10Accepted1ms496 KiB
11Accepted1ms500 KiB
12Accepted1ms388 KiB
13Accepted1ms316 KiB
14Accepted1ms580 KiB
15Accepted1ms508 KiB
16Accepted1ms316 KiB
17Accepted1ms316 KiB
18Accepted1ms316 KiB
subtask40/34
19Accepted282ms5784 KiB
20Accepted397ms6016 KiB
21Accepted370ms6024 KiB
22Accepted307ms6020 KiB
23Accepted293ms5940 KiB
24Accepted711ms5940 KiB
25Accepted263ms5940 KiB
26Accepted289ms5808 KiB
27Time limit exceeded2.082s5940 KiB
28Accepted584ms4408 KiB
29Accepted879ms4404 KiB
30Time limit exceeded2.082s4148 KiB
31Accepted712ms4404 KiB
32Accepted1.462s5948 KiB
33Accepted1.519s6008 KiB
subtask521/21
34Accepted104ms1332 KiB
35Accepted78ms1832 KiB
36Accepted68ms1588 KiB
37Accepted68ms1588 KiB
38Accepted67ms1832 KiB
39Accepted65ms1824 KiB
40Accepted166ms1588 KiB
41Accepted165ms1588 KiB
42Accepted39ms1076 KiB
43Accepted82ms1080 KiB
44Accepted79ms1076 KiB
45Accepted79ms1124 KiB
46Accepted48ms1076 KiB
47Accepted46ms1076 KiB
48Accepted61ms1336 KiB
49Accepted61ms1340 KiB
subtask60/22
50Accepted1.008s5940 KiB
51Accepted323ms5988 KiB
52Accepted284ms5940 KiB
53Accepted286ms6032 KiB
54Accepted280ms6020 KiB
55Accepted238ms5996 KiB
56Time limit exceeded2.099s5940 KiB
57Time limit exceeded2.088s5940 KiB
58Accepted300ms1588 KiB
59Accepted676ms4404 KiB
60Accepted797ms4404 KiB
61Accepted1.047s4596 KiB
62Accepted1.478s4564 KiB
63Accepted620ms4404 KiB
64Accepted1.475s6008 KiB
65Accepted1.542s6004 KiB
66Time limit exceeded2.075s5940 KiB