Submission #920866

#TimeUsernameProblemLanguageResultExecution timeMemory
920866thelegendary08Monthly railway pass (LMIO18_menesinis_bilietas)C++14
100 / 100
686 ms97252 KiB
#include<bits/stdc++.h> #define f0r(i,n) for(int i = 0;i<n;i++) #define pb push_back using namespace std; const int mxn = 500005; vector<int> adj[mxn]; bool vis[mxn]; vector<int>cur; void dfs(int u){ if(vis[u])return; vis[u] = 1; cur.pb(u); for(int x : adj[u])dfs(x); } int main(){ int n,m; cin>>n>>m; vector<pair<int,int>> bus; f0r(i, m){ int a,b; cin>>a>>b; char c; cin>>c; if(c == 'T'){ adj[--a].pb(--b); adj[b].pb(a); } else{ bus.pb({--a,--b}); } } f0r(i,n)vis[i] = 0; vector<vector<int>>ccs; f0r(i,n){ if(!vis[i]){ cur.clear(); dfs(i); ccs.pb(cur); } //f0r(j,n)cout<<vis[j]<<' '; //cout<<'\n'; //for(int x : cur)cout<<x<<' '; //cout<<'\n'; } int component[n]; f0r(i,ccs.size()){ for(int x : ccs[i]){ component[x] = i; } } //the size of component i is just ccs[i].size() set<int>adj[ccs.size()]; for(pair<int,int> p : bus){ int pa = p.first; int pb = p.second; if(component[pa] != component[pb]){ adj[component[pa]].insert(component[pb]); adj[component[pb]].insert(component[pa]); } } int ans = 0; f0r(i,ccs.size()){ //cout<<adj[i].size()<<' '; if(adj[i].size() == ccs.size() - 1)ans += ccs[i].size(); } cout<<ans; }

Compilation message (stderr)

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:2:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    2 | #define f0r(i,n) for(int i = 0;i<n;i++)
......
   50 |     f0r(i,ccs.size()){
      |         ~~~~~~~~~~~~             
menesinis_bilietas.cpp:50:5: note: in expansion of macro 'f0r'
   50 |     f0r(i,ccs.size()){
      |     ^~~
menesinis_bilietas.cpp:2:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    2 | #define f0r(i,n) for(int i = 0;i<n;i++)
......
   70 |     f0r(i,ccs.size()){
      |         ~~~~~~~~~~~~             
menesinis_bilietas.cpp:70:5: note: in expansion of macro 'f0r'
   70 |     f0r(i,ccs.size()){
      |     ^~~
#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...