104832024-04-03 11:30:28Valaki2Autópálya inflációcpp17Wrong answer 42/1001.195s13660 KiB
#include <bits/stdc++.h>
using namespace std;

#define distance distance1337

#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

const int maxn = 3100;
const int mod = 1e9 + 7;
const int k = 1; // log2 max c_i + epsilon

struct distance {
    bitset<1 + maxn> bs;
    distance() {
        bs = 0;
    }
    distance(int num) {
        if(num == -1) {
            bs.set();
        } else {
            bs = num;
        }
    }
    distance(bitset<1 + maxn> bs_) {
        bs = bs_;
    }
    bool operator < (const distance &other) const {
        // reversed
        for(int i = maxn; i >= 0; i--) {
            if(other.bs[i] ^ bs[i]) {
                if(other.bs[i] > bs[i]) {
                    return false;
                } else {
                    return true;
                }
            }
        }
        return false;
    }
    // debug
    void print() {
        cout << bs.to_ullong();
    }
};

const distance inf = distance(-1);

int n, m;
vector<pii > graph[1 + maxn];
distance dist[1 + maxn][1 + k];
bool done[1 + maxn][1 + k];
int steps[1 + maxn];

void solve() {
    cin >> n >> m;
    for(int i = 1; i <= m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        graph[a].pb(mp(b, c));
        graph[b].pb(mp(a, c));
    }
    queue<int> bfsq;
    bfsq.push(1);
    while(!bfsq.empty()) {
        int cur = bfsq.front();
        bfsq.pop();
        for(pii nei : graph[cur]) {
            if(nei.fi != 1 && steps[nei.fi] == 0) {
                bfsq.push(nei.fi);
                steps[nei.fi] = steps[cur] + 1;
            }
        }
    }
    priority_queue<pair<distance, pii > > q;
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= k; j++) {
            dist[i][j] = distance(-1);
        }
    }
    dist[1][0].bs = 0;
    q.push(mp(dist[1][0], mp(1, 0)));
    while(!q.empty()) {
        pii curpair = q.top().se;
        q.pop();
        int cur = curpair.fi, cur_steps = curpair.se;
        int cur_idx = cur_steps - steps[cur];
        // cout << cur << " " << cur_steps << " " << cur_idx << ":\n";
        if(done[cur][cur_idx]) {
            continue;
        }
        done[cur][cur_idx] = true;
        if(cur_steps >= n) {
            continue;
        }
        for(pii nei : graph[cur]) {
            int nei_idx = cur_steps + 1 - steps[nei.fi];
            if(nei_idx > k) {
                continue;
            }
            bitset<1 + maxn> tmp = (bitset<1 + maxn>(nei.se) << cur_steps);
            int carry = 0;
            for(int i = 0; i <= maxn; i++) {
                int sum = dist[cur][cur_idx].bs[i] + tmp[i] + carry;
                carry = sum / 2;
                tmp[i] = sum % 2;
            }
            distance neidist = distance(tmp);
            // distance neidist = distance(dist[cur][cur_idx].bs + (bitset<1 + maxn>(nei.se) << cur_steps));
            // reversed
            if(dist[nei.fi][nei_idx] < neidist) {
                dist[nei.fi][nei_idx] = neidist;
                q.push(mp(neidist, mp(nei.fi, cur_steps + 1)));
            }
        }
    }
    /*for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= k; j++) {
            if(dist[i][j].bs[maxn] == 0) {
                dist[i][j].print();
            } else {
                cout << "-1";
            }
            cout << " ";
        }
        cout << "\n";
    }*/
    for(int i = 2; i <= n; i++) {
        distance ans_bs(-1);
        for(int j = 0; j <= k; j++) {
            ans_bs = max(ans_bs, dist[i][j]);
        }
        int ans = 0;
        int coeff = 1;
        for(int i = 0; i <= maxn; i++) {
            ans += coeff * ans_bs.bs[i];
            ans %= mod;
            coeff = (2 * coeff) % mod;
                    }
        cout << ans % mod << "\n";
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted6ms6596 KiB
2Wrong answer1.141s10932 KiB
subtask28/8
3Accepted460ms7992 KiB
4Accepted328ms7876 KiB
5Accepted312ms8192 KiB
6Accepted437ms10040 KiB
7Accepted111ms8108 KiB
subtask30/15
8Accepted4ms7968 KiB
9Accepted6ms8256 KiB
10Accepted6ms8392 KiB
11Accepted6ms8328 KiB
12Accepted6ms8388 KiB
13Accepted6ms8560 KiB
14Accepted6ms8416 KiB
15Accepted4ms8452 KiB
16Accepted4ms8412 KiB
17Wrong answer4ms8184 KiB
18Wrong answer4ms8380 KiB
subtask434/34
19Accepted1.133s12496 KiB
20Accepted978ms10348 KiB
21Accepted1.004s11364 KiB
22Accepted1.113s11352 KiB
23Accepted1.083s12820 KiB
24Accepted810ms10220 KiB
25Accepted1.156s13052 KiB
26Accepted1.195s13072 KiB
27Accepted634ms9616 KiB
28Accepted254ms9508 KiB
29Accepted236ms9472 KiB
30Accepted136ms9668 KiB
31Accepted261ms9712 KiB
32Accepted303ms10024 KiB
33Accepted301ms10044 KiB
subtask50/21
34Accepted109ms9560 KiB
35Wrong answer232ms9828 KiB
36Wrong answer254ms10592 KiB
37Wrong answer254ms10588 KiB
38Wrong answer238ms10596 KiB
39Wrong answer239ms10444 KiB
40Wrong answer247ms9592 KiB
41Wrong answer247ms9804 KiB
42Accepted41ms9416 KiB
43Accepted28ms9420 KiB
44Accepted28ms9428 KiB
45Accepted28ms9444 KiB
46Accepted39ms9428 KiB
47Wrong answer37ms9428 KiB
48Wrong answer52ms9596 KiB
49Wrong answer52ms9572 KiB
subtask60/22
50Wrong answer781ms10660 KiB
51Wrong answer1.077s12096 KiB
52Wrong answer1.075s13600 KiB
53Wrong answer1.095s13604 KiB
54Wrong answer1.062s13660 KiB
55Wrong answer1.062s13624 KiB
56Wrong answer679ms10064 KiB
57Wrong answer680ms10064 KiB
58Accepted52ms9740 KiB
59Accepted250ms10116 KiB
60Accepted238ms10084 KiB
61Accepted226ms10020 KiB
62Wrong answer201ms10024 KiB
63Wrong answer257ms9996 KiB
64Wrong answer296ms10184 KiB
65Wrong answer296ms10444 KiB
66Accepted225ms10364 KiB