# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
213577 | 2020-03-26T08:03:37 Z | SamAnd | Monthly railway pass (LMIO18_menesinis_bilietas) | C++17 | 696 ms | 86184 KB |
#include <bits/stdc++.h> using namespace std; #define m_p make_pair const int N = 500005; int n, m; vector<int> a[N]; vector<pair<int, int> > v; int k; int c[N]; void dfs(int x) { c[x] = k; for (int i = 0; i < a[x].size(); ++i) { int h = a[x][i]; if (!c[h]) dfs(h); } } int q[N]; set<int> s[N]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < m; ++i) { int x, y; char ty; scanf("%d%d %c", &x, &y, &ty); if (ty == 'T') { a[x].push_back(y); a[y].push_back(x); } else { v.push_back(m_p(x, y)); } } for (int i = 1; i <= n; ++i) { if (!c[i]) { ++k; dfs(i); } } for (int i = 1; i <= n; ++i) q[c[i]]++; for (int i = 0; i < v.size(); ++i) { int x = v[i].first; int y = v[i].second; if (c[x] != c[y]) { s[c[x]].insert(c[y]); s[c[y]].insert(c[x]); } } int ans = 0; for (int i = 1; i <= k; ++i) { if (s[i].size() == k - 1) ans += q[i]; } printf("%d\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 456 ms | 58744 KB | Output is correct |
2 | Correct | 24 ms | 35584 KB | Output is correct |
3 | Correct | 24 ms | 35584 KB | Output is correct |
4 | Correct | 30 ms | 39168 KB | Output is correct |
5 | Correct | 24 ms | 35712 KB | Output is correct |
6 | Correct | 107 ms | 40892 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 39168 KB | Output is correct |
2 | Correct | 23 ms | 35584 KB | Output is correct |
3 | Correct | 24 ms | 35712 KB | Output is correct |
4 | Correct | 29 ms | 36352 KB | Output is correct |
5 | Correct | 24 ms | 35712 KB | Output is correct |
6 | Correct | 591 ms | 73880 KB | Output is correct |
7 | Correct | 696 ms | 86184 KB | Output is correct |
8 | Correct | 35 ms | 37376 KB | Output is correct |
9 | Correct | 44 ms | 38900 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 35584 KB | Output is correct |
2 | Correct | 23 ms | 35584 KB | Output is correct |
3 | Correct | 25 ms | 35584 KB | Output is correct |
4 | Correct | 26 ms | 35712 KB | Output is correct |
5 | Correct | 29 ms | 35840 KB | Output is correct |
6 | Correct | 26 ms | 35968 KB | Output is correct |
7 | Correct | 24 ms | 35584 KB | Output is correct |
8 | Correct | 23 ms | 35584 KB | Output is correct |
9 | Correct | 29 ms | 35968 KB | Output is correct |
10 | Correct | 23 ms | 35584 KB | Output is correct |
11 | Correct | 24 ms | 35584 KB | Output is correct |
12 | Correct | 24 ms | 35584 KB | Output is correct |
13 | Correct | 25 ms | 35712 KB | Output is correct |
14 | Correct | 25 ms | 35584 KB | Output is correct |
15 | Correct | 24 ms | 35712 KB | Output is correct |
16 | Correct | 24 ms | 35584 KB | Output is correct |
17 | Correct | 24 ms | 35584 KB | Output is correct |
18 | Correct | 23 ms | 35584 KB | Output is correct |
19 | Correct | 24 ms | 35712 KB | Output is correct |
20 | Correct | 29 ms | 36352 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 35584 KB | Output is correct |
2 | Correct | 23 ms | 35584 KB | Output is correct |
3 | Correct | 25 ms | 35584 KB | Output is correct |
4 | Correct | 26 ms | 35712 KB | Output is correct |
5 | Correct | 29 ms | 35840 KB | Output is correct |
6 | Correct | 26 ms | 35968 KB | Output is correct |
7 | Correct | 24 ms | 35584 KB | Output is correct |
8 | Correct | 23 ms | 35584 KB | Output is correct |
9 | Correct | 29 ms | 35968 KB | Output is correct |
10 | Correct | 23 ms | 35584 KB | Output is correct |
11 | Correct | 24 ms | 35584 KB | Output is correct |
12 | Correct | 24 ms | 35584 KB | Output is correct |
13 | Correct | 25 ms | 35712 KB | Output is correct |
14 | Correct | 25 ms | 35584 KB | Output is correct |
15 | Correct | 24 ms | 35712 KB | Output is correct |
16 | Correct | 37 ms | 36224 KB | Output is correct |
17 | Correct | 206 ms | 43960 KB | Output is correct |
18 | Correct | 101 ms | 39172 KB | Output is correct |
19 | Correct | 244 ms | 50532 KB | Output is correct |
20 | Correct | 81 ms | 38252 KB | Output is correct |
21 | Correct | 189 ms | 49076 KB | Output is correct |
22 | Correct | 24 ms | 35584 KB | Output is correct |
23 | Correct | 24 ms | 35584 KB | Output is correct |
24 | Correct | 23 ms | 35584 KB | Output is correct |
25 | Correct | 24 ms | 35712 KB | Output is correct |
26 | Correct | 29 ms | 36352 KB | Output is correct |
27 | Correct | 24 ms | 35712 KB | Output is correct |
28 | Correct | 35 ms | 37376 KB | Output is correct |
29 | Correct | 44 ms | 38900 KB | Output is correct |
30 | Correct | 107 ms | 40892 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 35584 KB | Output is correct |
2 | Correct | 23 ms | 35584 KB | Output is correct |
3 | Correct | 25 ms | 35584 KB | Output is correct |
4 | Correct | 26 ms | 35712 KB | Output is correct |
5 | Correct | 29 ms | 35840 KB | Output is correct |
6 | Correct | 26 ms | 35968 KB | Output is correct |
7 | Correct | 24 ms | 35584 KB | Output is correct |
8 | Correct | 23 ms | 35584 KB | Output is correct |
9 | Correct | 29 ms | 35968 KB | Output is correct |
10 | Correct | 23 ms | 35584 KB | Output is correct |
11 | Correct | 24 ms | 35584 KB | Output is correct |
12 | Correct | 24 ms | 35584 KB | Output is correct |
13 | Correct | 25 ms | 35712 KB | Output is correct |
14 | Correct | 25 ms | 35584 KB | Output is correct |
15 | Correct | 24 ms | 35712 KB | Output is correct |
16 | Correct | 37 ms | 36224 KB | Output is correct |
17 | Correct | 206 ms | 43960 KB | Output is correct |
18 | Correct | 101 ms | 39172 KB | Output is correct |
19 | Correct | 244 ms | 50532 KB | Output is correct |
20 | Correct | 81 ms | 38252 KB | Output is correct |
21 | Correct | 189 ms | 49076 KB | Output is correct |
22 | Correct | 456 ms | 58744 KB | Output is correct |
23 | Correct | 24 ms | 35584 KB | Output is correct |
24 | Correct | 24 ms | 35584 KB | Output is correct |
25 | Correct | 30 ms | 39168 KB | Output is correct |
26 | Correct | 23 ms | 35584 KB | Output is correct |
27 | Correct | 24 ms | 35712 KB | Output is correct |
28 | Correct | 29 ms | 36352 KB | Output is correct |
29 | Correct | 24 ms | 35712 KB | Output is correct |
30 | Correct | 591 ms | 73880 KB | Output is correct |
31 | Correct | 696 ms | 86184 KB | Output is correct |
32 | Correct | 64 ms | 39280 KB | Output is correct |
33 | Correct | 331 ms | 52068 KB | Output is correct |
34 | Correct | 222 ms | 45928 KB | Output is correct |
35 | Correct | 35 ms | 37376 KB | Output is correct |
36 | Correct | 44 ms | 38900 KB | Output is correct |
37 | Correct | 107 ms | 40892 KB | Output is correct |