Submission #235225

# Submission time Handle Problem Language Result Execution time Memory
235225 2020-05-27T12:45:21 Z rama_pang Monthly railway pass (LMIO18_menesinis_bilietas) C++14
100 / 100
207 ms 29668 KB
#include <bits/stdc++.h>
using namespace std;
using lint = long long;

const int MAXN = 500005;

int N, M;
vector<int> adj[MAXN];

int p[MAXN];
int Find(int x) {
  return p[x] == x ? x : p[x] = Find(p[x]);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  cin >> N >> M;
  iota(p, p + MAXN, 0);

  vector<pair<int, int>> edge;
  for (int i = 0; i < M; i++) {
    int u, v;
    string s;
    cin >> u >> v >> s;
    if (s == "T") {
      p[Find(u)] = Find(v);
    } else {
      edge.emplace_back(u, v);
    }
  }

  int cc = 0;
  for (int i = 1; i <= N; i++) {
    if (Find(i) == i) {
      cc++;
    }
  }

  vector<pair<int, int>> se;
  for (auto e : edge) {
    int u = e.first;
    int v = e.second;
    u = Find(u);
    v = Find(v);
    if (u == v) continue;
    se.emplace_back(min(u, v), max(u, v));
  }
  sort(begin(se), end(se));
  se.resize(unique(begin(se), end(se)) - begin(se));

  vector<int> deg(N + 1);
  for (auto i : se) {
    deg[i.first]++;
    deg[i.second]++;
  }

  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (deg[Find(i)] == cc - 1) {
      ans++;
    }
  }

  cout << ans << "\n";
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 195 ms 22008 KB Output is correct
2 Correct 13 ms 14080 KB Output is correct
3 Correct 13 ms 14080 KB Output is correct
4 Correct 15 ms 15872 KB Output is correct
5 Correct 13 ms 14080 KB Output is correct
6 Correct 65 ms 16376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 15872 KB Output is correct
2 Correct 13 ms 14080 KB Output is correct
3 Correct 14 ms 14080 KB Output is correct
4 Correct 15 ms 14336 KB Output is correct
5 Correct 13 ms 14080 KB Output is correct
6 Correct 154 ms 27236 KB Output is correct
7 Correct 198 ms 29668 KB Output is correct
8 Correct 18 ms 14592 KB Output is correct
9 Correct 23 ms 14976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14080 KB Output is correct
2 Correct 13 ms 14080 KB Output is correct
3 Correct 14 ms 14208 KB Output is correct
4 Correct 14 ms 14208 KB Output is correct
5 Correct 16 ms 14464 KB Output is correct
6 Correct 14 ms 14208 KB Output is correct
7 Correct 12 ms 14080 KB Output is correct
8 Correct 14 ms 14080 KB Output is correct
9 Correct 16 ms 14464 KB Output is correct
10 Correct 13 ms 14080 KB Output is correct
11 Correct 16 ms 14080 KB Output is correct
12 Correct 13 ms 14080 KB Output is correct
13 Correct 14 ms 14208 KB Output is correct
14 Correct 13 ms 14080 KB Output is correct
15 Correct 14 ms 14080 KB Output is correct
16 Correct 13 ms 14080 KB Output is correct
17 Correct 13 ms 14080 KB Output is correct
18 Correct 13 ms 14080 KB Output is correct
19 Correct 14 ms 14080 KB Output is correct
20 Correct 15 ms 14336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14080 KB Output is correct
2 Correct 13 ms 14080 KB Output is correct
3 Correct 14 ms 14208 KB Output is correct
4 Correct 14 ms 14208 KB Output is correct
5 Correct 16 ms 14464 KB Output is correct
6 Correct 14 ms 14208 KB Output is correct
7 Correct 12 ms 14080 KB Output is correct
8 Correct 14 ms 14080 KB Output is correct
9 Correct 16 ms 14464 KB Output is correct
10 Correct 13 ms 14080 KB Output is correct
11 Correct 16 ms 14080 KB Output is correct
12 Correct 13 ms 14080 KB Output is correct
13 Correct 14 ms 14208 KB Output is correct
14 Correct 13 ms 14080 KB Output is correct
15 Correct 14 ms 14080 KB Output is correct
16 Correct 23 ms 14976 KB Output is correct
17 Correct 151 ms 27484 KB Output is correct
18 Correct 65 ms 19816 KB Output is correct
19 Correct 88 ms 20724 KB Output is correct
20 Correct 55 ms 17648 KB Output is correct
21 Correct 81 ms 19308 KB Output is correct
22 Correct 13 ms 14080 KB Output is correct
23 Correct 13 ms 14080 KB Output is correct
24 Correct 13 ms 14080 KB Output is correct
25 Correct 14 ms 14080 KB Output is correct
26 Correct 15 ms 14336 KB Output is correct
27 Correct 13 ms 14080 KB Output is correct
28 Correct 18 ms 14592 KB Output is correct
29 Correct 23 ms 14976 KB Output is correct
30 Correct 65 ms 16376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14080 KB Output is correct
2 Correct 13 ms 14080 KB Output is correct
3 Correct 14 ms 14208 KB Output is correct
4 Correct 14 ms 14208 KB Output is correct
5 Correct 16 ms 14464 KB Output is correct
6 Correct 14 ms 14208 KB Output is correct
7 Correct 12 ms 14080 KB Output is correct
8 Correct 14 ms 14080 KB Output is correct
9 Correct 16 ms 14464 KB Output is correct
10 Correct 13 ms 14080 KB Output is correct
11 Correct 16 ms 14080 KB Output is correct
12 Correct 13 ms 14080 KB Output is correct
13 Correct 14 ms 14208 KB Output is correct
14 Correct 13 ms 14080 KB Output is correct
15 Correct 14 ms 14080 KB Output is correct
16 Correct 23 ms 14976 KB Output is correct
17 Correct 151 ms 27484 KB Output is correct
18 Correct 65 ms 19816 KB Output is correct
19 Correct 88 ms 20724 KB Output is correct
20 Correct 55 ms 17648 KB Output is correct
21 Correct 81 ms 19308 KB Output is correct
22 Correct 195 ms 22008 KB Output is correct
23 Correct 13 ms 14080 KB Output is correct
24 Correct 13 ms 14080 KB Output is correct
25 Correct 15 ms 15872 KB Output is correct
26 Correct 13 ms 14080 KB Output is correct
27 Correct 14 ms 14080 KB Output is correct
28 Correct 15 ms 14336 KB Output is correct
29 Correct 13 ms 14080 KB Output is correct
30 Correct 154 ms 27236 KB Output is correct
31 Correct 198 ms 29668 KB Output is correct
32 Correct 37 ms 15996 KB Output is correct
33 Correct 207 ms 28768 KB Output is correct
34 Correct 88 ms 17912 KB Output is correct
35 Correct 18 ms 14592 KB Output is correct
36 Correct 23 ms 14976 KB Output is correct
37 Correct 65 ms 16376 KB Output is correct