Submission #920977

#TimeUsernameProblemLanguageResultExecution timeMemory
920977zhehanMonthly railway pass (LMIO18_menesinis_bilietas)C++14
6 / 100
1274 ms162304 KiB
#include <bits/stdc++.h> using namespace std; int parent[500000]; int f(int a){ if(parent[a]=a){ return a; } return parent[a]=f(parent[a]); } void u(int a,int b){ parent[f(a)]=f(b); } int main() { int n,m; cin>>n>>m; for(int i{1};i<n+1;++i){ parent[i]=i; } map<int,vector<int>> ma; for(int i{};i<m;++i){ int a,b; char c; cin>>a>>b>>c; if(c=='T'){ u(a,b); }else{ ma[a].push_back(b); ma[b].push_back(a); } } map<int,set<int>> mf; map<int,int> cc; for(int i{1};i<n+1;++i){ cc[parent[i]]++; for(auto e:ma[i]){ mf[parent[i]].insert(parent[e]); } } int counter=0; for(auto e:mf){ if(mf.size()==e.second.size()+1){ counter+=cc[e.first]; } } cout<<counter; return 0; }

Compilation message (stderr)

menesinis_bilietas.cpp: In function 'int f(int)':
menesinis_bilietas.cpp:8:17: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
    8 |     if(parent[a]=a){
      |        ~~~~~~~~~^~
#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...