Submission #906442

#TimeUsernameProblemLanguageResultExecution timeMemory
906442pccMonthly railway pass (LMIO18_menesinis_bilietas)C++14
100 / 100
639 ms116064 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define pii pair<int,int> #define fs first #define sc second #define tlll tuple<ll,ll,ll> const int mxn = 5e5+10; vector<pii> edges; int N,M; bitset<mxn> able; int dsu[mxn],sz[mxn]; unordered_set<int> paths[mxn]; int root(int k){ return k == dsu[k]?k:dsu[k] = root(dsu[k]); } void onion(int a,int b){ a = root(a),b = root(b); if(a == b)return; if(sz[a]<sz[b])swap(a,b); dsu[b] = a; sz[a] += sz[b]; return; } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>N>>M; for(int i = 1;i<=N;i++){ dsu[i] = i,sz[i] = 1; } for(int i = 0;i<M;i++){ int a,b; char c; cin>>a>>b>>c; if(c == 'T')onion(a,b); else edges.push_back({a,b}); } int gcnt = 0; for(auto &i:edges){ i.fs = root(i.fs); i.sc = root(i.sc); if(i.fs == i.sc)continue; paths[i.fs].insert(i.sc); paths[i.sc].insert(i.fs); } for(int i = 1;i<=N;i++)if(dsu[i] == i)gcnt++; for(int i = 1;i<=N;i++){ if(dsu[i] != i)continue; if(paths[i].size()+1 == gcnt)able[i] = true; } int ans = 0; for(int i = 1;i<=N;i++)if(able[root(i)])ans++; cout<<ans; }

Compilation message (stderr)

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:57:24: warning: comparison of integer expressions of different signedness: 'std::unordered_set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |   if(paths[i].size()+1 == gcnt)able[i] = true;
      |      ~~~~~~~~~~~~~~~~~~^~~~~~~
#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...