Submission #826036

# Submission time Handle Problem Language Result Execution time Memory
826036 2023-08-15T10:02:59 Z AlphaMale06 Monthly railway pass (LMIO18_menesinis_bilietas) C++14
100 / 100
451 ms 74392 KB
#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define mp make_pair
#define pb push_back

const int N = 500005;
int p[N];
int sz[N];
set<int> adj[N];
vector<pair<int, int>> paid;

void make(int v){p[v]=v; sz[v]=1;}

int rep(int v){
    if(p[v]==v)return v;
    return p[v]=rep(p[v]);
}

void unite(int v, int u){
    v=rep(v);
    u=rep(u);
    if(u==v)return;
    if(sz[u]>sz[v]){
        swap(u, v);
    }
    p[u]=v;
    sz[v]+=sz[u];
}



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i=1; i<=n; i++){
        make(i);
    }
    for(int i=0; i< m; i++){
        int x, y;
        char a;
        cin >> x >> y >> a;
        if(a=='T'){
            unite(x, y);
        }
        else paid.pb(mp(x, y));
    }
    for(int i=0; i< paid.size(); i++){
        int x=paid[i].F;
        int y=paid[i].S;
        x=rep(x);
        y=rep(y);
        if(x==y)continue;
        adj[x].insert(y);
        adj[y].insert(x);
    }
    int ans=0;
    int cnt=0;
    for(int i=1; i<=n; i++){
        if(p[i]==i)cnt++;
    }
    for(int i=1; i<=n; i++){
        if(p[i]==i){
            if(adj[i].size()==cnt-1)ans+=sz[i];
        }
    }
    cout << ans << '\n';
}

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:54:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for(int i=0; i< paid.size(); i++){
      |                  ~^~~~~~~~~~~~~
menesinis_bilietas.cpp:70:29: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   70 |             if(adj[i].size()==cnt-1)ans+=sz[i];
      |                ~~~~~~~~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 89 ms 29456 KB Output is correct
2 Correct 12 ms 23884 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 15 ms 27396 KB Output is correct
5 Correct 13 ms 23892 KB Output is correct
6 Correct 37 ms 26168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 27396 KB Output is correct
2 Correct 13 ms 23892 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23892 KB Output is correct
5 Correct 16 ms 24588 KB Output is correct
6 Correct 438 ms 61952 KB Output is correct
7 Correct 451 ms 74392 KB Output is correct
8 Correct 18 ms 25556 KB Output is correct
9 Correct 29 ms 27028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23884 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23892 KB Output is correct
5 Correct 16 ms 24588 KB Output is correct
6 Correct 12 ms 23812 KB Output is correct
7 Correct 12 ms 23768 KB Output is correct
8 Correct 12 ms 23892 KB Output is correct
9 Correct 13 ms 23952 KB Output is correct
10 Correct 14 ms 24020 KB Output is correct
11 Correct 14 ms 24124 KB Output is correct
12 Correct 12 ms 23764 KB Output is correct
13 Correct 12 ms 23812 KB Output is correct
14 Correct 14 ms 24192 KB Output is correct
15 Correct 11 ms 23764 KB Output is correct
16 Correct 12 ms 23768 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 12 ms 23920 KB Output is correct
19 Correct 12 ms 23832 KB Output is correct
20 Correct 12 ms 23892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23812 KB Output is correct
2 Correct 12 ms 23768 KB Output is correct
3 Correct 12 ms 23892 KB Output is correct
4 Correct 13 ms 23952 KB Output is correct
5 Correct 14 ms 24020 KB Output is correct
6 Correct 14 ms 24124 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23812 KB Output is correct
9 Correct 14 ms 24192 KB Output is correct
10 Correct 11 ms 23764 KB Output is correct
11 Correct 12 ms 23768 KB Output is correct
12 Correct 12 ms 23764 KB Output is correct
13 Correct 12 ms 23920 KB Output is correct
14 Correct 12 ms 23832 KB Output is correct
15 Correct 12 ms 23892 KB Output is correct
16 Correct 12 ms 23884 KB Output is correct
17 Correct 11 ms 23764 KB Output is correct
18 Correct 12 ms 23764 KB Output is correct
19 Correct 12 ms 23892 KB Output is correct
20 Correct 16 ms 24588 KB Output is correct
21 Correct 13 ms 23892 KB Output is correct
22 Correct 18 ms 25556 KB Output is correct
23 Correct 29 ms 27028 KB Output is correct
24 Correct 37 ms 26168 KB Output is correct
25 Correct 17 ms 24456 KB Output is correct
26 Correct 93 ms 31480 KB Output is correct
27 Correct 42 ms 27452 KB Output is correct
28 Correct 128 ms 38720 KB Output is correct
29 Correct 39 ms 26404 KB Output is correct
30 Correct 95 ms 36584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23812 KB Output is correct
2 Correct 12 ms 23768 KB Output is correct
3 Correct 12 ms 23892 KB Output is correct
4 Correct 13 ms 23952 KB Output is correct
5 Correct 14 ms 24020 KB Output is correct
6 Correct 14 ms 24124 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23812 KB Output is correct
9 Correct 14 ms 24192 KB Output is correct
10 Correct 11 ms 23764 KB Output is correct
11 Correct 12 ms 23768 KB Output is correct
12 Correct 12 ms 23764 KB Output is correct
13 Correct 12 ms 23920 KB Output is correct
14 Correct 12 ms 23832 KB Output is correct
15 Correct 12 ms 23892 KB Output is correct
16 Correct 17 ms 24456 KB Output is correct
17 Correct 93 ms 31480 KB Output is correct
18 Correct 42 ms 27452 KB Output is correct
19 Correct 128 ms 38720 KB Output is correct
20 Correct 39 ms 26404 KB Output is correct
21 Correct 95 ms 36584 KB Output is correct
22 Correct 89 ms 29456 KB Output is correct
23 Correct 12 ms 23884 KB Output is correct
24 Correct 11 ms 23764 KB Output is correct
25 Correct 15 ms 27396 KB Output is correct
26 Correct 12 ms 23764 KB Output is correct
27 Correct 12 ms 23892 KB Output is correct
28 Correct 16 ms 24588 KB Output is correct
29 Correct 13 ms 23892 KB Output is correct
30 Correct 438 ms 61952 KB Output is correct
31 Correct 451 ms 74392 KB Output is correct
32 Correct 18 ms 25556 KB Output is correct
33 Correct 29 ms 27028 KB Output is correct
34 Correct 37 ms 26168 KB Output is correct
35 Correct 31 ms 26772 KB Output is correct
36 Correct 147 ms 37692 KB Output is correct
37 Correct 49 ms 28500 KB Output is correct