-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathABC352F.cpp
42 lines (40 loc) · 985 Bytes
/
ABC352F.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <bits/extc++.h>
using namespace std;
namespace pbds = __gnu_pbds;
using ui = unsigned int;
using uli = unsigned long long int;
using li = long long int;
using uc = unsigned char;
using usi = unsigned short int;
int main(void) {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
size_t n, m;
cin >> n >> m;
array<vector<vector<uc>>, 65536> d;
vector<vector<uc>, usi> e;
{
vector<pair<uc, uc>> nxt(n, {255, numeric_limits<uc>::max()});
while (m--) {
usi a, b, c;
cin >> a >> b >> c;
--a, --b;
if (nxt[b].second > c) nxt[b] = {a, c};
}
vector<bool> vis(n);
for (uc i = 0; i < n; ++i)
if (!vis[i]) {
uc p = i;
vector<uc> r;
usi t = 0;
while (p != 255) {
r.emplace_back(p);
vis[p] = true;
t = (t << nxt[p].second) | 1;
p = nxt[p].first;
}
d[t].push_back(r);
e.emplace_back(r, t);
}
}
return 0;
}