답안 #825915

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
825915 2023-08-15T09:16:27 Z AlphaMale06 Monthly railway pass (LMIO18_menesinis_bilietas) C++14
75 / 100
389 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];
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];
    reps.erase(reps.find(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);
        reps.insert(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;
        int mn=min(x, y);
        int mx=max(x, y);
        adj[x].insert(mp(mn, mx));
        adj[y].insert(mp(mn, mx));
    }
    int ans=0;
    for(auto it = reps.begin(); it!=reps.end(); it++){
        int node=*it;
        if(adj[node].size()==reps.size()-1){
            ans+=sz[node];
        }
    }
    cout << ans << '\n';
}

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:57: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]
   57 |     for(int i=0; i< paid.size(); i++){
      |                  ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 389 ms 251456 KB Output is correct
2 Correct 91 ms 235032 KB Output is correct
3 Correct 92 ms 235140 KB Output is correct
4 Correct 192 ms 260888 KB Output is correct
5 Correct 112 ms 235852 KB Output is correct
6 Correct 115 ms 235576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 192 ms 260888 KB Output is correct
2 Correct 112 ms 235852 KB Output is correct
3 Correct 89 ms 235156 KB Output is correct
4 Correct 95 ms 235216 KB Output is correct
5 Correct 94 ms 235936 KB Output is correct
6 Runtime error 242 ms 262144 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 235032 KB Output is correct
2 Correct 92 ms 235140 KB Output is correct
3 Correct 89 ms 235156 KB Output is correct
4 Correct 95 ms 235216 KB Output is correct
5 Correct 94 ms 235936 KB Output is correct
6 Correct 91 ms 235080 KB Output is correct
7 Correct 95 ms 235172 KB Output is correct
8 Correct 93 ms 235312 KB Output is correct
9 Correct 92 ms 235228 KB Output is correct
10 Correct 97 ms 235324 KB Output is correct
11 Correct 94 ms 235456 KB Output is correct
12 Correct 90 ms 235200 KB Output is correct
13 Correct 90 ms 235120 KB Output is correct
14 Correct 98 ms 235500 KB Output is correct
15 Correct 97 ms 235080 KB Output is correct
16 Correct 93 ms 235216 KB Output is correct
17 Correct 90 ms 235148 KB Output is correct
18 Correct 94 ms 235308 KB Output is correct
19 Correct 90 ms 235144 KB Output is correct
20 Correct 91 ms 235176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 235080 KB Output is correct
2 Correct 95 ms 235172 KB Output is correct
3 Correct 93 ms 235312 KB Output is correct
4 Correct 92 ms 235228 KB Output is correct
5 Correct 97 ms 235324 KB Output is correct
6 Correct 94 ms 235456 KB Output is correct
7 Correct 90 ms 235200 KB Output is correct
8 Correct 90 ms 235120 KB Output is correct
9 Correct 98 ms 235500 KB Output is correct
10 Correct 97 ms 235080 KB Output is correct
11 Correct 93 ms 235216 KB Output is correct
12 Correct 90 ms 235148 KB Output is correct
13 Correct 94 ms 235308 KB Output is correct
14 Correct 90 ms 235144 KB Output is correct
15 Correct 91 ms 235176 KB Output is correct
16 Correct 91 ms 235032 KB Output is correct
17 Correct 92 ms 235140 KB Output is correct
18 Correct 89 ms 235156 KB Output is correct
19 Correct 95 ms 235216 KB Output is correct
20 Correct 94 ms 235936 KB Output is correct
21 Correct 112 ms 235852 KB Output is correct
22 Correct 115 ms 235576 KB Output is correct
23 Correct 98 ms 235808 KB Output is correct
24 Correct 191 ms 243572 KB Output is correct
25 Correct 125 ms 238844 KB Output is correct
26 Correct 205 ms 250032 KB Output is correct
27 Correct 123 ms 237692 KB Output is correct
28 Correct 197 ms 248096 KB Output is correct
29 Correct 99 ms 237688 KB Output is correct
30 Correct 110 ms 239176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 235080 KB Output is correct
2 Correct 95 ms 235172 KB Output is correct
3 Correct 93 ms 235312 KB Output is correct
4 Correct 92 ms 235228 KB Output is correct
5 Correct 97 ms 235324 KB Output is correct
6 Correct 94 ms 235456 KB Output is correct
7 Correct 90 ms 235200 KB Output is correct
8 Correct 90 ms 235120 KB Output is correct
9 Correct 98 ms 235500 KB Output is correct
10 Correct 97 ms 235080 KB Output is correct
11 Correct 93 ms 235216 KB Output is correct
12 Correct 90 ms 235148 KB Output is correct
13 Correct 94 ms 235308 KB Output is correct
14 Correct 90 ms 235144 KB Output is correct
15 Correct 91 ms 235176 KB Output is correct
16 Correct 98 ms 235808 KB Output is correct
17 Correct 191 ms 243572 KB Output is correct
18 Correct 125 ms 238844 KB Output is correct
19 Correct 205 ms 250032 KB Output is correct
20 Correct 123 ms 237692 KB Output is correct
21 Correct 197 ms 248096 KB Output is correct
22 Correct 389 ms 251456 KB Output is correct
23 Correct 91 ms 235032 KB Output is correct
24 Correct 92 ms 235140 KB Output is correct
25 Correct 192 ms 260888 KB Output is correct
26 Correct 89 ms 235156 KB Output is correct
27 Correct 95 ms 235216 KB Output is correct
28 Correct 94 ms 235936 KB Output is correct
29 Correct 112 ms 235852 KB Output is correct
30 Runtime error 242 ms 262144 KB Execution killed with signal 9
31 Halted 0 ms 0 KB -