Submission #393281

#TimeUsernameProblemLanguageResultExecution timeMemory
393281lukameladzeMonthly railway pass (LMIO18_menesinis_bilietas)C++14
100 / 100
983 ms102068 KiB
#include <bits/stdc++.h> #define f first #define s second #define pb push_back using namespace std; const int N=5e5+5; long long n,pr[N],ans,mn,m,sz[N],p[N],a,b,cnt[N],cntt,xx; char ch; vector <long long> v[N]; vector <pair <long long, long long> > v1; map <long long, long long> connected[N]; int get_col(int a) { if (a==p[a]) return a; return p[a]=get_col(p[a]); } void col(int a, int b) { a=get_col(a); b=get_col(b); if (a==b) return ; if (sz[a]<sz[b]) swap(a,b); sz[a]+=sz[b]; sz[b]=0; p[b]=a; } int main() { cin>>n>>m; for (int i=1; i<=n; i++) { p[i]=i; sz[i]=1; } for (int i=1; i<=m; i++) { cin>>a>>b>>ch; if (ch=='T') { v[a].pb(b); col(a,b); xx=a; v[b].pb(a); } else { v1.pb({a,b}); } } for (int i=0; i<v1.size(); i++) { a=v1[i].f; b=v1[i].s; a=get_col(a); b=get_col(b); if (a==b) continue; if (!connected[a][b]) cnt[a]++, cnt[b]++, connected[a][b]=1,connected[b][a]=1;//,cout<<a<<" "<<b<<endl; } if (!v1.size()) { if (sz[get_col(xx)]==n) { cout<<n<<endl; return 0; } else cout<<0<<endl; return 0; } for (int i=1; i<=n; i++) { if (p[i]!=i) continue; // cout<<i<<" "<<sz[i]<<endl; cntt++; } for (int i=1; i<=n; i++) { if (p[i]!=i) continue; if (cntt-1==cnt[i]) { ans+=sz[i]; } } cout<<ans<<endl; }

Compilation message (stderr)

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:43:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |      for (int i=0; i<v1.size(); i++) {
      |                    ~^~~~~~~~~~
#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...