10483 | 2024-04-03 11:30:28 | Valaki2 | Autópálya infláció | cpp17 | Wrong answer 42/100 | 1.195s | 13660 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();
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 6ms | 6596 KiB | ||||
2 | Wrong answer | 1.141s | 10932 KiB | ||||
subtask2 | 8/8 | ||||||
3 | Accepted | 460ms | 7992 KiB | ||||
4 | Accepted | 328ms | 7876 KiB | ||||
5 | Accepted | 312ms | 8192 KiB | ||||
6 | Accepted | 437ms | 10040 KiB | ||||
7 | Accepted | 111ms | 8108 KiB | ||||
subtask3 | 0/15 | ||||||
8 | Accepted | 4ms | 7968 KiB | ||||
9 | Accepted | 6ms | 8256 KiB | ||||
10 | Accepted | 6ms | 8392 KiB | ||||
11 | Accepted | 6ms | 8328 KiB | ||||
12 | Accepted | 6ms | 8388 KiB | ||||
13 | Accepted | 6ms | 8560 KiB | ||||
14 | Accepted | 6ms | 8416 KiB | ||||
15 | Accepted | 4ms | 8452 KiB | ||||
16 | Accepted | 4ms | 8412 KiB | ||||
17 | Wrong answer | 4ms | 8184 KiB | ||||
18 | Wrong answer | 4ms | 8380 KiB | ||||
subtask4 | 34/34 | ||||||
19 | Accepted | 1.133s | 12496 KiB | ||||
20 | Accepted | 978ms | 10348 KiB | ||||
21 | Accepted | 1.004s | 11364 KiB | ||||
22 | Accepted | 1.113s | 11352 KiB | ||||
23 | Accepted | 1.083s | 12820 KiB | ||||
24 | Accepted | 810ms | 10220 KiB | ||||
25 | Accepted | 1.156s | 13052 KiB | ||||
26 | Accepted | 1.195s | 13072 KiB | ||||
27 | Accepted | 634ms | 9616 KiB | ||||
28 | Accepted | 254ms | 9508 KiB | ||||
29 | Accepted | 236ms | 9472 KiB | ||||
30 | Accepted | 136ms | 9668 KiB | ||||
31 | Accepted | 261ms | 9712 KiB | ||||
32 | Accepted | 303ms | 10024 KiB | ||||
33 | Accepted | 301ms | 10044 KiB | ||||
subtask5 | 0/21 | ||||||
34 | Accepted | 109ms | 9560 KiB | ||||
35 | Wrong answer | 232ms | 9828 KiB | ||||
36 | Wrong answer | 254ms | 10592 KiB | ||||
37 | Wrong answer | 254ms | 10588 KiB | ||||
38 | Wrong answer | 238ms | 10596 KiB | ||||
39 | Wrong answer | 239ms | 10444 KiB | ||||
40 | Wrong answer | 247ms | 9592 KiB | ||||
41 | Wrong answer | 247ms | 9804 KiB | ||||
42 | Accepted | 41ms | 9416 KiB | ||||
43 | Accepted | 28ms | 9420 KiB | ||||
44 | Accepted | 28ms | 9428 KiB | ||||
45 | Accepted | 28ms | 9444 KiB | ||||
46 | Accepted | 39ms | 9428 KiB | ||||
47 | Wrong answer | 37ms | 9428 KiB | ||||
48 | Wrong answer | 52ms | 9596 KiB | ||||
49 | Wrong answer | 52ms | 9572 KiB | ||||
subtask6 | 0/22 | ||||||
50 | Wrong answer | 781ms | 10660 KiB | ||||
51 | Wrong answer | 1.077s | 12096 KiB | ||||
52 | Wrong answer | 1.075s | 13600 KiB | ||||
53 | Wrong answer | 1.095s | 13604 KiB | ||||
54 | Wrong answer | 1.062s | 13660 KiB | ||||
55 | Wrong answer | 1.062s | 13624 KiB | ||||
56 | Wrong answer | 679ms | 10064 KiB | ||||
57 | Wrong answer | 680ms | 10064 KiB | ||||
58 | Accepted | 52ms | 9740 KiB | ||||
59 | Accepted | 250ms | 10116 KiB | ||||
60 | Accepted | 238ms | 10084 KiB | ||||
61 | Accepted | 226ms | 10020 KiB | ||||
62 | Wrong answer | 201ms | 10024 KiB | ||||
63 | Wrong answer | 257ms | 9996 KiB | ||||
64 | Wrong answer | 296ms | 10184 KiB | ||||
65 | Wrong answer | 296ms | 10444 KiB | ||||
66 | Accepted | 225ms | 10364 KiB |