Submission #973988

#TimeUsernameProblemLanguageResultExecution timeMemory
973988AtabayRajabliMonthly railway pass (LMIO18_menesinis_bilietas)C++17
16 / 100
539 ms97880 KiB
#include <bits/stdc++.h> #define int ll #define all(v) v.begin(), v.end() // author : a1abay using namespace std; typedef long long ll; typedef long double ld; const int sz = 5e5 + 5; const int inf = 1e9 + 7; int n, m, u, v, w; int p[sz]; char c; set<int> g[sz]; int par(int x) { if(p[x] < 0) return x; return p[x] = par(p[x]); } bool join(int u, int v) { u = par(u), v = par(v); if(u == v) return 0; if(p[u] > p[v]) swap(u, v); p[u] += p[v]; p[v] = u; return 1; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); memset(p, -1, sizeof(p)); cin >> n >> m; vector<array<int, 2>> e; for(int i = 1; i <= m; i++) { cin >> u >> v >> c; if(c == 'T') join(u, v); else e.push_back({u, v}); } for(auto x : e) { u = x[0], v = x[1]; u = par(u), v = par(v); g[u].insert(v); g[v].insert(u); } set<int> s; for(int i = 1; i <= n; i++) s.insert(par(i)); int cnt = 0; for(int i = 1; i <= n; i++) cnt += s.size() - 1 == g[par(i)].size(); cout << cnt; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...