10476 | 2024-04-03 10:29:50 | Valaki2 | Autópálya infláció | cpp17 | Runtime error 8/100 | 185ms | 10700 KiB |
#include <bits/stdc++.h>
using namespace std;
#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;
int n, m;
vector<pii > graph[1 + maxn];
int pow2[1 + maxn];
int dist[1 + maxn];
void dfs(int cur, int par, int depth) {
for(pii nei : graph[cur]) {
if(nei.fi != par) {
dist[nei.fi] = (dist[cur] + nei.se * pow2[depth]) % mod;
dfs(nei.fi, cur, depth + 1);
}
}
}
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));
}
pow2[0] = 1;
for(int i = 1; i <= n; i++) {
pow2[i] = (2 * pow2[i - 1]) % mod;
}
dfs(1, -1, 0);
for(int i = 2; i <= n; i++) {
cout << dist[i] << "\n";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Runtime error | 4ms | 4304 KiB | ||||
2 | Runtime error | 7ms | 5396 KiB | ||||
subtask2 | 8/8 | ||||||
3 | Accepted | 4ms | 3084 KiB | ||||
4 | Accepted | 4ms | 3332 KiB | ||||
5 | Accepted | 4ms | 3580 KiB | ||||
6 | Accepted | 4ms | 3764 KiB | ||||
7 | Accepted | 4ms | 4456 KiB | ||||
subtask3 | 0/15 | ||||||
8 | Accepted | 3ms | 3820 KiB | ||||
9 | Runtime error | 3ms | 6108 KiB | ||||
10 | Runtime error | 4ms | 6244 KiB | ||||
11 | Runtime error | 4ms | 6388 KiB | ||||
12 | Runtime error | 4ms | 6352 KiB | ||||
13 | Runtime error | 4ms | 6344 KiB | ||||
14 | Runtime error | 4ms | 6360 KiB | ||||
15 | Runtime error | 4ms | 6492 KiB | ||||
16 | Runtime error | 4ms | 6568 KiB | ||||
17 | Runtime error | 4ms | 6576 KiB | ||||
18 | Runtime error | 4ms | 6696 KiB | ||||
subtask4 | 0/34 | ||||||
19 | Runtime error | 6ms | 7460 KiB | ||||
20 | Runtime error | 8ms | 7536 KiB | ||||
21 | Runtime error | 8ms | 7600 KiB | ||||
22 | Runtime error | 6ms | 7680 KiB | ||||
23 | Runtime error | 6ms | 7636 KiB | ||||
24 | Runtime error | 9ms | 7984 KiB | ||||
25 | Runtime error | 6ms | 8096 KiB | ||||
26 | Runtime error | 6ms | 8124 KiB | ||||
27 | Runtime error | 6ms | 7960 KiB | ||||
28 | Runtime error | 4ms | 7968 KiB | ||||
29 | Runtime error | 4ms | 8004 KiB | ||||
30 | Runtime error | 4ms | 7824 KiB | ||||
31 | Runtime error | 4ms | 8004 KiB | ||||
32 | Runtime error | 6ms | 8268 KiB | ||||
33 | Runtime error | 6ms | 8332 KiB | ||||
subtask5 | 0/21 | ||||||
34 | Runtime error | 185ms | 7756 KiB | ||||
35 | Runtime error | 4ms | 7956 KiB | ||||
36 | Runtime error | 4ms | 8116 KiB | ||||
37 | Runtime error | 4ms | 8244 KiB | ||||
38 | Runtime error | 4ms | 8268 KiB | ||||
39 | Runtime error | 4ms | 8308 KiB | ||||
40 | Runtime error | 4ms | 8336 KiB | ||||
41 | Runtime error | 4ms | 8364 KiB | ||||
42 | Runtime error | 4ms | 8308 KiB | ||||
43 | Runtime error | 4ms | 8212 KiB | ||||
44 | Runtime error | 4ms | 8376 KiB | ||||
45 | Runtime error | 4ms | 8236 KiB | ||||
46 | Runtime error | 4ms | 8252 KiB | ||||
47 | Runtime error | 4ms | 8256 KiB | ||||
48 | Runtime error | 4ms | 8352 KiB | ||||
49 | Runtime error | 4ms | 8456 KiB | ||||
subtask6 | 0/22 | ||||||
50 | Runtime error | 35ms | 9160 KiB | ||||
51 | Runtime error | 7ms | 9148 KiB | ||||
52 | Runtime error | 6ms | 9264 KiB | ||||
53 | Runtime error | 7ms | 9516 KiB | ||||
54 | Runtime error | 6ms | 9488 KiB | ||||
55 | Runtime error | 6ms | 9748 KiB | ||||
56 | Runtime error | 6ms | 9484 KiB | ||||
57 | Runtime error | 6ms | 9576 KiB | ||||
58 | Runtime error | 4ms | 9204 KiB | ||||
59 | Runtime error | 6ms | 9744 KiB | ||||
60 | Runtime error | 4ms | 10048 KiB | ||||
61 | Runtime error | 4ms | 9952 KiB | ||||
62 | Runtime error | 4ms | 10084 KiB | ||||
63 | Runtime error | 4ms | 10144 KiB | ||||
64 | Runtime error | 7ms | 10596 KiB | ||||
65 | Runtime error | 6ms | 10700 KiB | ||||
66 | Runtime error | 6ms | 10652 KiB |