Submission #921019

#TimeUsernameProblemLanguageResultExecution timeMemory
921019gelastropodMonthly railway pass (LMIO18_menesinis_bilietas)C++14
16 / 100
574 ms89284 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int nSets; vector<int> dsu; int find(int x) { if (dsu[x] == x) return x; return dsu[x] = find(dsu[x]); } void join(int a, int b) { a = find(a), b = find(b); if (a == b) return; dsu[a] = b; nSets--; } signed main() { int N, M, a, b, ans = 0; cin >> N >> M; char t; for (int i = 0; i < N; i++) dsu.push_back(i); nSets = N; vector<vector<pair<int, bool>>> adjlist(N, vector<pair<int, bool>>()); for (int i = 0; i < M; i++) { cin >> a >> b >> t; a--, b--; adjlist[a].push_back(pair<int, int>(b, t == 'A')); adjlist[b].push_back(pair<int, int>(a, t == 'A')); if (t == 'T') join(a, b); } vector<set<int>> btradjlist(N, set<int>()); for (int i = 0; i < N; i++) { for (auto j : adjlist[i]) { if (j.second && i != find(j.first)) btradjlist[find(i)].insert(find(j.first)); } } for (int i = 0; i < N; i++) { if (btradjlist[find(i)].size() == nSets - 1) ans++; } cout << ans << '\n'; }

Compilation message (stderr)

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:48:40: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   48 |         if (btradjlist[find(i)].size() == nSets - 1) 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...