# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
795920 | 2023-07-27T22:18:12 Z | vjudge1 | Monthly railway pass (LMIO18_menesinis_bilietas) | C++17 | 654 ms | 88652 KB |
#include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<map> using namespace std; #define mp make_pair #define pb push_back #define pii pair<int, int> const int maxN = 1e6 + 10; int n, m; vector<int> v[maxN]; int cmp[maxN]; int a[maxN], b[maxN]; int other[maxN], tot[maxN]; int cur; map<pii, bool> mapa; void dfs(int x, int comp) { cmp[x] = comp; tot[comp]++; for (int i: v[x]) { if (!cmp[i]) { dfs(i, comp); } } } int main() { cin >> n >> m; for (int i = 1; i<= m; i++) { int x, y; char ch; scanf("%d %d %c",&x,&y, &ch); if (ch == 'T') { v[x].pb(y); v[y].pb(x); } else { a[++cur] = x; b[cur] = y; } } int cmpCount = 0; for (int i = 1; i <= n; i++) { if (!cmp[i]) { dfs(i, ++cmpCount); } } if (cmpCount == 1) { cout << n << endl; return 0; } for (int i = 1; i <= cur; i++) { if (cmp[a[i]] != cmp[b[i]]) { int x = cmp[a[i]]; int y = cmp[b[i]]; pii edge = mp(x, y); if (mapa[edge] == false) { mapa[edge] = true; other[x]++; mapa[mp(y, x)] = true; other[y]++; } } } int ans = 0; for (int i = 1; i<= cmpCount; i++) { if (other[i] == cmpCount - 1) ans+= tot[i]; } cout << ans << endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 265 ms | 49200 KB | Output is correct |
2 | Correct | 12 ms | 23800 KB | Output is correct |
3 | Correct | 12 ms | 23764 KB | Output is correct |
4 | Correct | 18 ms | 27520 KB | Output is correct |
5 | Correct | 15 ms | 23796 KB | Output is correct |
6 | Correct | 60 ms | 28968 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 27520 KB | Output is correct |
2 | Correct | 15 ms | 23796 KB | Output is correct |
3 | Correct | 13 ms | 23764 KB | Output is correct |
4 | Correct | 13 ms | 23896 KB | Output is correct |
5 | Correct | 19 ms | 24828 KB | Output is correct |
6 | Correct | 555 ms | 72436 KB | Output is correct |
7 | Correct | 654 ms | 88652 KB | Output is correct |
8 | Correct | 23 ms | 26068 KB | Output is correct |
9 | Correct | 38 ms | 28080 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 23800 KB | Output is correct |
2 | Correct | 12 ms | 23764 KB | Output is correct |
3 | Correct | 13 ms | 23764 KB | Output is correct |
4 | Correct | 13 ms | 23896 KB | Output is correct |
5 | Correct | 19 ms | 24828 KB | Output is correct |
6 | Correct | 13 ms | 23724 KB | Output is correct |
7 | Correct | 13 ms | 23900 KB | Output is correct |
8 | Correct | 14 ms | 23892 KB | Output is correct |
9 | Correct | 14 ms | 23892 KB | Output is correct |
10 | Correct | 15 ms | 24020 KB | Output is correct |
11 | Correct | 19 ms | 24148 KB | Output is correct |
12 | Correct | 14 ms | 23764 KB | Output is correct |
13 | Correct | 16 ms | 23796 KB | Output is correct |
14 | Correct | 17 ms | 24276 KB | Output is correct |
15 | Correct | 12 ms | 23748 KB | Output is correct |
16 | Correct | 13 ms | 23888 KB | Output is correct |
17 | Correct | 12 ms | 23756 KB | Output is correct |
18 | Correct | 14 ms | 23892 KB | Output is correct |
19 | Correct | 17 ms | 23824 KB | Output is correct |
20 | Correct | 14 ms | 24020 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 23724 KB | Output is correct |
2 | Correct | 13 ms | 23900 KB | Output is correct |
3 | Correct | 14 ms | 23892 KB | Output is correct |
4 | Correct | 14 ms | 23892 KB | Output is correct |
5 | Correct | 15 ms | 24020 KB | Output is correct |
6 | Correct | 19 ms | 24148 KB | Output is correct |
7 | Correct | 14 ms | 23764 KB | Output is correct |
8 | Correct | 16 ms | 23796 KB | Output is correct |
9 | Correct | 17 ms | 24276 KB | Output is correct |
10 | Correct | 12 ms | 23748 KB | Output is correct |
11 | Correct | 13 ms | 23888 KB | Output is correct |
12 | Correct | 12 ms | 23756 KB | Output is correct |
13 | Correct | 14 ms | 23892 KB | Output is correct |
14 | Correct | 17 ms | 23824 KB | Output is correct |
15 | Correct | 14 ms | 24020 KB | Output is correct |
16 | Correct | 12 ms | 23800 KB | Output is correct |
17 | Correct | 12 ms | 23764 KB | Output is correct |
18 | Correct | 13 ms | 23764 KB | Output is correct |
19 | Correct | 13 ms | 23896 KB | Output is correct |
20 | Correct | 19 ms | 24828 KB | Output is correct |
21 | Correct | 15 ms | 23796 KB | Output is correct |
22 | Correct | 23 ms | 26068 KB | Output is correct |
23 | Correct | 38 ms | 28080 KB | Output is correct |
24 | Correct | 60 ms | 28968 KB | Output is correct |
25 | Correct | 20 ms | 24448 KB | Output is correct |
26 | Correct | 158 ms | 32212 KB | Output is correct |
27 | Correct | 55 ms | 26740 KB | Output is correct |
28 | Correct | 180 ms | 42388 KB | Output is correct |
29 | Correct | 52 ms | 26704 KB | Output is correct |
30 | Correct | 150 ms | 40436 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 23724 KB | Output is correct |
2 | Correct | 13 ms | 23900 KB | Output is correct |
3 | Correct | 14 ms | 23892 KB | Output is correct |
4 | Correct | 14 ms | 23892 KB | Output is correct |
5 | Correct | 15 ms | 24020 KB | Output is correct |
6 | Correct | 19 ms | 24148 KB | Output is correct |
7 | Correct | 14 ms | 23764 KB | Output is correct |
8 | Correct | 16 ms | 23796 KB | Output is correct |
9 | Correct | 17 ms | 24276 KB | Output is correct |
10 | Correct | 12 ms | 23748 KB | Output is correct |
11 | Correct | 13 ms | 23888 KB | Output is correct |
12 | Correct | 12 ms | 23756 KB | Output is correct |
13 | Correct | 14 ms | 23892 KB | Output is correct |
14 | Correct | 17 ms | 23824 KB | Output is correct |
15 | Correct | 14 ms | 24020 KB | Output is correct |
16 | Correct | 20 ms | 24448 KB | Output is correct |
17 | Correct | 158 ms | 32212 KB | Output is correct |
18 | Correct | 55 ms | 26740 KB | Output is correct |
19 | Correct | 180 ms | 42388 KB | Output is correct |
20 | Correct | 52 ms | 26704 KB | Output is correct |
21 | Correct | 150 ms | 40436 KB | Output is correct |
22 | Correct | 265 ms | 49200 KB | Output is correct |
23 | Correct | 12 ms | 23800 KB | Output is correct |
24 | Correct | 12 ms | 23764 KB | Output is correct |
25 | Correct | 18 ms | 27520 KB | Output is correct |
26 | Correct | 13 ms | 23764 KB | Output is correct |
27 | Correct | 13 ms | 23896 KB | Output is correct |
28 | Correct | 19 ms | 24828 KB | Output is correct |
29 | Correct | 15 ms | 23796 KB | Output is correct |
30 | Correct | 555 ms | 72436 KB | Output is correct |
31 | Correct | 654 ms | 88652 KB | Output is correct |
32 | Correct | 23 ms | 26068 KB | Output is correct |
33 | Correct | 38 ms | 28080 KB | Output is correct |
34 | Correct | 60 ms | 28968 KB | Output is correct |
35 | Correct | 46 ms | 27980 KB | Output is correct |
36 | Correct | 213 ms | 41768 KB | Output is correct |
37 | Correct | 111 ms | 34048 KB | Output is correct |