Submission #393269

# Submission time Handle Problem Language Result Execution time Memory
393269 2021-04-23T05:47:07 Z lukameladze Monthly railway pass (LMIO18_menesinis_bilietas) C++14
6 / 100
1010 ms 108444 KB
#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;
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 (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);
               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;
     }
     for (int i=1; i<=n; i++) {
          if (p[i]!=i) continue;
          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

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:41: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]
   41 |      for (int i=0; i<v1.size(); i++) {
      |                    ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 753 ms 62120 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 42828 KB Output is correct
2 Correct 21 ms 35536 KB Output is correct
3 Correct 19 ms 35676 KB Output is correct
4 Correct 28 ms 36556 KB Output is correct
5 Correct 23 ms 35660 KB Output is correct
6 Correct 777 ms 87356 KB Output is correct
7 Correct 1010 ms 108444 KB Output is correct
8 Correct 38 ms 38216 KB Output is correct
9 Correct 53 ms 40120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 35536 KB Output is correct
2 Correct 19 ms 35676 KB Output is correct
3 Correct 28 ms 36556 KB Output is correct
4 Correct 20 ms 35508 KB Output is correct
5 Correct 20 ms 35524 KB Output is correct
6 Correct 22 ms 35680 KB Output is correct
7 Incorrect 24 ms 35788 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 35508 KB Output is correct
2 Correct 20 ms 35524 KB Output is correct
3 Correct 22 ms 35680 KB Output is correct
4 Incorrect 24 ms 35788 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 35508 KB Output is correct
2 Correct 20 ms 35524 KB Output is correct
3 Correct 22 ms 35680 KB Output is correct
4 Incorrect 24 ms 35788 KB Output isn't correct
5 Halted 0 ms 0 KB -