160812025-03-30 20:05:53szilAutópálya inflációcpp17Wrong answer 15/1001.468s6224 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();
    }
    vector<bigint> dist_last(n+1);
    dist_last[1].clear();
    vis[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[j]) ok = false;
        }
        if (ok && is_ok == -1) is_ok = 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
2Accepted237ms6032 KiB
subtask20/8
3Accepted133ms4616 KiB
4Wrong answer153ms4628 KiB
5Wrong answer166ms4608 KiB
6Accepted125ms4608 KiB
7Wrong answer1.335s4612 KiB
subtask315/15
8Accepted1ms316 KiB
9Accepted1ms316 KiB
10Accepted1ms316 KiB
11Accepted1ms316 KiB
12Accepted1ms316 KiB
13Accepted1ms316 KiB
14Accepted1ms316 KiB
15Accepted1ms316 KiB
16Accepted1ms328 KiB
17Accepted1ms316 KiB
18Accepted1ms316 KiB
subtask40/34
19Accepted250ms6028 KiB
20Wrong answer275ms6036 KiB
21Wrong answer291ms6036 KiB
22Accepted234ms6036 KiB
23Accepted252ms6032 KiB
24Wrong answer361ms6040 KiB
25Accepted231ms6036 KiB
26Accepted238ms6020 KiB
27Wrong answer185ms6040 KiB
28Wrong answer384ms4608 KiB
29Wrong answer505ms4624 KiB
30Wrong answer1.166s4180 KiB
31Wrong answer433ms4596 KiB
32Wrong answer737ms6012 KiB
33Wrong answer689ms6012 KiB
subtask50/21
34Wrong answer43ms1568 KiB
35Accepted57ms1836 KiB
36Accepted57ms1844 KiB
37Accepted57ms1836 KiB
38Accepted56ms1840 KiB
39Accepted56ms1840 KiB
40Wrong answer54ms1588 KiB
41Wrong answer54ms1844 KiB
42Wrong answer26ms1136 KiB
43Wrong answer43ms1076 KiB
44Wrong answer45ms1136 KiB
45Wrong answer45ms1136 KiB
46Wrong answer29ms1136 KiB
47Wrong answer28ms1108 KiB
48Wrong answer39ms1352 KiB
49Wrong answer39ms1332 KiB
subtask60/22
50Wrong answer398ms6224 KiB
51Accepted250ms6028 KiB
52Accepted236ms6028 KiB
53Accepted277ms6172 KiB
54Accepted252ms6028 KiB
55Accepted256ms6056 KiB
56Wrong answer185ms6132 KiB
57Wrong answer174ms5816 KiB
58Wrong answer156ms1824 KiB
59Wrong answer474ms4616 KiB
60Wrong answer546ms4616 KiB
61Wrong answer653ms4616 KiB
62Wrong answer767ms4404 KiB
63Wrong answer405ms4576 KiB
64Wrong answer704ms6004 KiB
65Wrong answer839ms6008 KiB
66Wrong answer1.468s5936 KiB