Submission #825829

# Submission time Handle Problem Language Result Execution time Memory
825829 2023-08-15T08:35:41 Z AlphaMale06 Monthly railway pass (LMIO18_menesinis_bilietas) C++14
10 / 100
357 ms 262144 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 = 5000005;
int p[N];
int sz[N];
set<int> reps;
set<pair<int, int>, less<pair<int, int>>> adj[N];
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[v]=u;
    sz[u]+=sz[v];
    reps.erase(reps.find(v));
}



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> free;
    vector<pair<int, int>> paid;
    for(int i=1; i<=n; i++){
        make(i);
        reps.insert(i);
    }
    for(int i=0; i< m; i++){
        int x, y;
        char a;
        cin >> x >> y >> a;
        if(a=='T'){
            free.pb(mp(x, y));
        }
        else paid.pb(mp(x, y));
    }

    for(int i=0; i<free.size(); i++){
        unite(free[i].F, free[i].S);
    }
    for(int i=0; i< paid.size(); i++){
        int x=paid[i].F;
        int y=paid[i].S;
        x=rep(x);
        y=rep(y);
        adj[x].insert(mp(x, y));
        adj[y].insert(mp(x, y));
        adj[y].insert(mp(y, x));
        adj[x].insert(mp(y, x));
    }
    int ans=0;
    for(auto it = reps.begin(); it!=reps.end(); it++){
        int node=*it;
        if(adj[node].size()==2*(reps.size()-1)){
            ans+=sz[node];
        }
    }
    cout << ans << '\n';
}

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:58: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]
   58 |     for(int i=0; i<free.size(); i++){
      |                  ~^~~~~~~~~~~~
menesinis_bilietas.cpp:61: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]
   61 |     for(int i=0; i< paid.size(); i++){
      |                  ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 357 ms 262000 KB Output is correct
2 Correct 95 ms 235068 KB Output is correct
3 Correct 103 ms 235292 KB Output is correct
4 Correct 191 ms 260888 KB Output is correct
5 Correct 96 ms 235832 KB Output is correct
6 Correct 128 ms 239644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 191 ms 260888 KB Output is correct
2 Correct 96 ms 235832 KB Output is correct
3 Correct 96 ms 235124 KB Output is correct
4 Correct 97 ms 235340 KB Output is correct
5 Correct 103 ms 236684 KB Output is correct
6 Runtime error 239 ms 262144 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 95 ms 235068 KB Output is correct
2 Correct 103 ms 235292 KB Output is correct
3 Correct 96 ms 235124 KB Output is correct
4 Correct 97 ms 235340 KB Output is correct
5 Correct 103 ms 236684 KB Output is correct
6 Correct 98 ms 235112 KB Output is correct
7 Correct 96 ms 235136 KB Output is correct
8 Correct 94 ms 235248 KB Output is correct
9 Correct 96 ms 235200 KB Output is correct
10 Incorrect 98 ms 235416 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 98 ms 235112 KB Output is correct
2 Correct 96 ms 235136 KB Output is correct
3 Correct 94 ms 235248 KB Output is correct
4 Correct 96 ms 235200 KB Output is correct
5 Incorrect 98 ms 235416 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 98 ms 235112 KB Output is correct
2 Correct 96 ms 235136 KB Output is correct
3 Correct 94 ms 235248 KB Output is correct
4 Correct 96 ms 235200 KB Output is correct
5 Incorrect 98 ms 235416 KB Output isn't correct
6 Halted 0 ms 0 KB -