Submission #198451

#TimeUsernameProblemLanguageResultExecution timeMemory
198451oolimryMonthly railway pass (LMIO18_menesinis_bilietas)C++14
100 / 100
598 ms68972 KiB
#include <bits/stdc++.h> using namespace std; static int p[500005]; int numSets; int findSet(int u){ if(p[u] == u) return u; else{ p[u] = findSet(p[u]); return p[u]; } } void unionSet(int u, int v){ u = findSet(u); v = findSet(v); if(u == v) return; p[u] = v; numSets--; } typedef pair<int,int> ii; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; numSets = n; unordered_set<int> edges[n]; for(int i = 0;i < n;i++) p[i] = i; vector<ii> bus; for(int i = 0;i < m;i++){ int u, v; char c; cin >> u >> v >> c; u--; v--; if(c == 'T'){ unionSet(u,v); } else{ bus.push_back(ii(u,v)); } } for(ii e : bus){ int u = findSet(e.first); int v = findSet(e.second); if(u == v) continue; edges[u].insert(v); edges[v].insert(u); } int ans = 0; for(int i = 0;i < n;i++){ if(numSets - 1 == edges[findSet(i)].size()) ans++; } cout << ans << "\n"; }

Compilation message (stderr)

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:53:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(numSets - 1 == edges[findSet(i)].size()) ans++;
      ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...