답안 #393281

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393281 2021-04-23T06:12:27 Z lukameladze Monthly railway pass (LMIO18_menesinis_bilietas) C++14
100 / 100
983 ms 102068 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,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

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++) {
      |                    ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 666 ms 55164 KB Output is correct
2 Correct 22 ms 35532 KB Output is correct
3 Correct 21 ms 35500 KB Output is correct
4 Correct 23 ms 42868 KB Output is correct
5 Correct 20 ms 35660 KB Output is correct
6 Correct 161 ms 42792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 42868 KB Output is correct
2 Correct 20 ms 35660 KB Output is correct
3 Correct 20 ms 35476 KB Output is correct
4 Correct 23 ms 35660 KB Output is correct
5 Correct 27 ms 36588 KB Output is correct
6 Correct 812 ms 83076 KB Output is correct
7 Correct 983 ms 102068 KB Output is correct
8 Correct 44 ms 37952 KB Output is correct
9 Correct 55 ms 39828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 35532 KB Output is correct
2 Correct 21 ms 35500 KB Output is correct
3 Correct 20 ms 35476 KB Output is correct
4 Correct 23 ms 35660 KB Output is correct
5 Correct 27 ms 36588 KB Output is correct
6 Correct 20 ms 35560 KB Output is correct
7 Correct 21 ms 35512 KB Output is correct
8 Correct 22 ms 35660 KB Output is correct
9 Correct 23 ms 35744 KB Output is correct
10 Correct 26 ms 36036 KB Output is correct
11 Correct 25 ms 35956 KB Output is correct
12 Correct 20 ms 35524 KB Output is correct
13 Correct 20 ms 35532 KB Output is correct
14 Correct 28 ms 36064 KB Output is correct
15 Correct 20 ms 35532 KB Output is correct
16 Correct 20 ms 35532 KB Output is correct
17 Correct 20 ms 35524 KB Output is correct
18 Correct 25 ms 35660 KB Output is correct
19 Correct 21 ms 35532 KB Output is correct
20 Correct 22 ms 35792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 35560 KB Output is correct
2 Correct 21 ms 35512 KB Output is correct
3 Correct 22 ms 35660 KB Output is correct
4 Correct 23 ms 35744 KB Output is correct
5 Correct 26 ms 36036 KB Output is correct
6 Correct 25 ms 35956 KB Output is correct
7 Correct 20 ms 35524 KB Output is correct
8 Correct 20 ms 35532 KB Output is correct
9 Correct 28 ms 36064 KB Output is correct
10 Correct 20 ms 35532 KB Output is correct
11 Correct 20 ms 35532 KB Output is correct
12 Correct 20 ms 35524 KB Output is correct
13 Correct 25 ms 35660 KB Output is correct
14 Correct 21 ms 35532 KB Output is correct
15 Correct 22 ms 35792 KB Output is correct
16 Correct 22 ms 35532 KB Output is correct
17 Correct 21 ms 35500 KB Output is correct
18 Correct 20 ms 35476 KB Output is correct
19 Correct 23 ms 35660 KB Output is correct
20 Correct 27 ms 36588 KB Output is correct
21 Correct 20 ms 35660 KB Output is correct
22 Correct 44 ms 37952 KB Output is correct
23 Correct 55 ms 39828 KB Output is correct
24 Correct 161 ms 42792 KB Output is correct
25 Correct 39 ms 36432 KB Output is correct
26 Correct 310 ms 48144 KB Output is correct
27 Correct 124 ms 41196 KB Output is correct
28 Correct 289 ms 55700 KB Output is correct
29 Correct 101 ms 39228 KB Output is correct
30 Correct 291 ms 53880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 35560 KB Output is correct
2 Correct 21 ms 35512 KB Output is correct
3 Correct 22 ms 35660 KB Output is correct
4 Correct 23 ms 35744 KB Output is correct
5 Correct 26 ms 36036 KB Output is correct
6 Correct 25 ms 35956 KB Output is correct
7 Correct 20 ms 35524 KB Output is correct
8 Correct 20 ms 35532 KB Output is correct
9 Correct 28 ms 36064 KB Output is correct
10 Correct 20 ms 35532 KB Output is correct
11 Correct 20 ms 35532 KB Output is correct
12 Correct 20 ms 35524 KB Output is correct
13 Correct 25 ms 35660 KB Output is correct
14 Correct 21 ms 35532 KB Output is correct
15 Correct 22 ms 35792 KB Output is correct
16 Correct 39 ms 36432 KB Output is correct
17 Correct 310 ms 48144 KB Output is correct
18 Correct 124 ms 41196 KB Output is correct
19 Correct 289 ms 55700 KB Output is correct
20 Correct 101 ms 39228 KB Output is correct
21 Correct 291 ms 53880 KB Output is correct
22 Correct 666 ms 55164 KB Output is correct
23 Correct 22 ms 35532 KB Output is correct
24 Correct 21 ms 35500 KB Output is correct
25 Correct 23 ms 42868 KB Output is correct
26 Correct 20 ms 35476 KB Output is correct
27 Correct 23 ms 35660 KB Output is correct
28 Correct 27 ms 36588 KB Output is correct
29 Correct 20 ms 35660 KB Output is correct
30 Correct 812 ms 83076 KB Output is correct
31 Correct 983 ms 102068 KB Output is correct
32 Correct 44 ms 37952 KB Output is correct
33 Correct 55 ms 39828 KB Output is correct
34 Correct 161 ms 42792 KB Output is correct
35 Correct 85 ms 40612 KB Output is correct
36 Correct 474 ms 58208 KB Output is correct
37 Correct 282 ms 49304 KB Output is correct