Submission #219460

#TimeUsernameProblemLanguageResultExecution timeMemory
219460quocnguyen1012Monthly railway pass (LMIO18_menesinis_bilietas)C++14
100 / 100
413 ms49504 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back using namespace std; typedef long long ll; typedef pair<int, int> ii; const int maxn = 5e5 + 5; vector<int> adj[maxn], train[maxn]; int comp[maxn], cc = 0; vector<ii> bus; int N, M; bool vis[maxn]; void dfs(int u) { vis[u] = true; comp[u] = cc; for(int v : train[u]) if(!vis[v]){ dfs(v); } } signed main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("A.INP", "r", stdin); freopen("A.OUT", "w", stdout); #endif // LOCAL cin >> N >> M; while(M--){ int u, v; cin >> u >> v; char type; cin >> type; if(type == 'T'){ train[u].pb(v); train[v].pb(u); } else{ bus.eb(u, v); } } for(int i = 1; i <= N; ++i){ if(!vis[i]){ ++cc; dfs(i); } } for(auto & all : bus){ int u = comp[all.fi]; int v = comp[all.se]; if(u == v) continue; adj[u].eb(v); adj[v].eb(u); } for(int i = 1; i <= cc; ++i){ sort(adj[i].begin(), adj[i].end()); adj[i].erase(unique(adj[i].begin(), adj[i].end()), adj[i].end()); } int res = 0; for(int i = 1; i <= N; ++i){ if(adj[comp[i]].size() == cc - 1) ++res; } cout << res; }

Compilation message (stderr)

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:67:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(adj[comp[i]].size() == cc - 1) ++res;
        ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
#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...