2750 | 2023-01-20 18:58:18 | Catt | Varázserdő | cpp17 | Accepted 100/100 | 2.265s | 205284 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
int main() {
ll n,m;
cin >> n >> m;
vector<pair<ll, pair<ll, ll>> > g(m);
for(ll i = 0; i < m; i++) {
ll x,y,z;
cin >> x >> y >> z;
g[i] = {z, {x, y}};
}
vector<map<ll, ll> > v(n+1);
ll mo = 0;
sort(g.begin(), g.end());
for(ll i = 0; i < m; i++) {
ll x,y,z;
z = g[i].first, x = g[i].second.first, y = g[i].second.second;
mo += v[x][z-1] + v[y][z-1] + 2;
mo %= MOD;
v[x][z] += v[y][z-1] + 1;
v[x][z] %= MOD;
v[y][z] += v[x][z-1] + 1;
v[y][z] %= MOD;
}
cout << (mo + MOD - m) % MOD;
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 356 KiB | ||||
2 | Accepted | 3ms | 400 KiB | ||||
3 | Accepted | 3ms | 532 KiB | ||||
subtask2 | 7/7 | ||||||
4 | Accepted | 3ms | 744 KiB | ||||
5 | Accepted | 4ms | 612 KiB | ||||
6 | Accepted | 16ms | 3100 KiB | ||||
7 | Accepted | 17ms | 3700 KiB | ||||
8 | Accepted | 1.046s | 165756 KiB | ||||
9 | Accepted | 1.146s | 156992 KiB | ||||
10 | Accepted | 930ms | 147656 KiB | ||||
11 | Accepted | 1s | 141028 KiB | ||||
12 | Accepted | 855ms | 138144 KiB | ||||
13 | Accepted | 947ms | 138084 KiB | ||||
subtask3 | 9/9 | ||||||
14 | Accepted | 3ms | 888 KiB | ||||
15 | Accepted | 4ms | 896 KiB | ||||
16 | Accepted | 159ms | 24128 KiB | ||||
17 | Accepted | 690ms | 48196 KiB | ||||
18 | Accepted | 1.985s | 166960 KiB | ||||
19 | Accepted | 1.271s | 126536 KiB | ||||
20 | Accepted | 1.386s | 129764 KiB | ||||
subtask4 | 14/14 | ||||||
21 | Accepted | 3ms | 632 KiB | ||||
22 | Accepted | 3ms | 504 KiB | ||||
23 | Accepted | 3ms | 356 KiB | ||||
24 | Accepted | 3ms | 356 KiB | ||||
subtask5 | 20/20 | ||||||
25 | Accepted | 4ms | 876 KiB | ||||
26 | Accepted | 9ms | 1784 KiB | ||||
27 | Accepted | 8ms | 1272 KiB | ||||
28 | Accepted | 9ms | 1648 KiB | ||||
29 | Accepted | 9ms | 1636 KiB | ||||
30 | Accepted | 9ms | 1636 KiB | ||||
31 | Accepted | 8ms | 1124 KiB | ||||
32 | Accepted | 8ms | 1272 KiB | ||||
subtask6 | 50/50 | ||||||
33 | Accepted | 18ms | 3564 KiB | ||||
34 | Accepted | 246ms | 32228 KiB | ||||
35 | Accepted | 1.126s | 42788 KiB | ||||
36 | Accepted | 1.167s | 45376 KiB | ||||
37 | Accepted | 1.631s | 167140 KiB | ||||
38 | Accepted | 2.134s | 184548 KiB | ||||
39 | Accepted | 2.265s | 205284 KiB | ||||
40 | Accepted | 1.784s | 189028 KiB | ||||
41 | Accepted | 1.57s | 89700 KiB |