Submission #213577

#TimeUsernameProblemLanguageResultExecution timeMemory
213577SamAndMonthly railway pass (LMIO18_menesinis_bilietas)C++17
100 / 100
696 ms86184 KiB
#include <bits/stdc++.h> using namespace std; #define m_p make_pair const int N = 500005; int n, m; vector<int> a[N]; vector<pair<int, int> > v; int k; int c[N]; void dfs(int x) { c[x] = k; for (int i = 0; i < a[x].size(); ++i) { int h = a[x][i]; if (!c[h]) dfs(h); } } int q[N]; set<int> s[N]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < m; ++i) { int x, y; char ty; scanf("%d%d %c", &x, &y, &ty); if (ty == 'T') { a[x].push_back(y); a[y].push_back(x); } else { v.push_back(m_p(x, y)); } } for (int i = 1; i <= n; ++i) { if (!c[i]) { ++k; dfs(i); } } for (int i = 1; i <= n; ++i) q[c[i]]++; for (int i = 0; i < v.size(); ++i) { int x = v[i].first; int y = v[i].second; if (c[x] != c[y]) { s[c[x]].insert(c[y]); s[c[y]].insert(c[x]); } } int ans = 0; for (int i = 1; i <= k; ++i) { if (s[i].size() == k - 1) ans += q[i]; } printf("%d\n", ans); return 0; }

Compilation message (stderr)

menesinis_bilietas.cpp: In function 'void dfs(int)':
menesinis_bilietas.cpp:15:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a[x].size(); ++i)
                     ~~^~~~~~~~~~~~~
menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:54:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
menesinis_bilietas.cpp:67:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (s[i].size() == k - 1)
             ~~~~~~~~~~~~^~~~~~~~
menesinis_bilietas.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
menesinis_bilietas.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d %c", &x, &y, &ty);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...