답안 #825962

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
825962 2023-08-15T09:35:32 Z AlphaMale06 Monthly railway pass (LMIO18_menesinis_bilietas) C++14
75 / 100
301 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;
    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];
        }
    }
    //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++){
      |                  ~^~~~~~~~~~~~~
menesinis_bilietas.cpp:75:29: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, int>, std::less<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   75 |             if(adj[i].size()==cnt-1)ans+=sz[i];
      |                ~~~~~~~~~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 171 ms 237644 KB Output is correct
2 Correct 93 ms 235056 KB Output is correct
3 Correct 91 ms 235140 KB Output is correct
4 Correct 101 ms 238836 KB Output is correct
5 Correct 92 ms 235180 KB Output is correct
6 Correct 121 ms 235236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 238836 KB Output is correct
2 Correct 92 ms 235180 KB Output is correct
3 Correct 104 ms 235040 KB Output is correct
4 Correct 91 ms 235144 KB Output is correct
5 Correct 95 ms 235968 KB Output is correct
6 Runtime error 301 ms 262144 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 235056 KB Output is correct
2 Correct 91 ms 235140 KB Output is correct
3 Correct 104 ms 235040 KB Output is correct
4 Correct 91 ms 235144 KB Output is correct
5 Correct 95 ms 235968 KB Output is correct
6 Correct 93 ms 235152 KB Output is correct
7 Correct 92 ms 235156 KB Output is correct
8 Correct 103 ms 235248 KB Output is correct
9 Correct 92 ms 235272 KB Output is correct
10 Correct 95 ms 235528 KB Output is correct
11 Correct 92 ms 235416 KB Output is correct
12 Correct 101 ms 235088 KB Output is correct
13 Correct 90 ms 235068 KB Output is correct
14 Correct 115 ms 235568 KB Output is correct
15 Correct 102 ms 235156 KB Output is correct
16 Correct 91 ms 235196 KB Output is correct
17 Correct 88 ms 235084 KB Output is correct
18 Correct 94 ms 235272 KB Output is correct
19 Correct 94 ms 235200 KB Output is correct
20 Correct 91 ms 235288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 235152 KB Output is correct
2 Correct 92 ms 235156 KB Output is correct
3 Correct 103 ms 235248 KB Output is correct
4 Correct 92 ms 235272 KB Output is correct
5 Correct 95 ms 235528 KB Output is correct
6 Correct 92 ms 235416 KB Output is correct
7 Correct 101 ms 235088 KB Output is correct
8 Correct 90 ms 235068 KB Output is correct
9 Correct 115 ms 235568 KB Output is correct
10 Correct 102 ms 235156 KB Output is correct
11 Correct 91 ms 235196 KB Output is correct
12 Correct 88 ms 235084 KB Output is correct
13 Correct 94 ms 235272 KB Output is correct
14 Correct 94 ms 235200 KB Output is correct
15 Correct 91 ms 235288 KB Output is correct
16 Correct 93 ms 235056 KB Output is correct
17 Correct 91 ms 235140 KB Output is correct
18 Correct 104 ms 235040 KB Output is correct
19 Correct 91 ms 235144 KB Output is correct
20 Correct 95 ms 235968 KB Output is correct
21 Correct 92 ms 235180 KB Output is correct
22 Correct 121 ms 235236 KB Output is correct
23 Correct 97 ms 235720 KB Output is correct
24 Correct 205 ms 239664 KB Output is correct
25 Correct 137 ms 237416 KB Output is correct
26 Correct 235 ms 248284 KB Output is correct
27 Correct 155 ms 236804 KB Output is correct
28 Correct 183 ms 246080 KB Output is correct
29 Correct 103 ms 236888 KB Output is correct
30 Correct 112 ms 238356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 235152 KB Output is correct
2 Correct 92 ms 235156 KB Output is correct
3 Correct 103 ms 235248 KB Output is correct
4 Correct 92 ms 235272 KB Output is correct
5 Correct 95 ms 235528 KB Output is correct
6 Correct 92 ms 235416 KB Output is correct
7 Correct 101 ms 235088 KB Output is correct
8 Correct 90 ms 235068 KB Output is correct
9 Correct 115 ms 235568 KB Output is correct
10 Correct 102 ms 235156 KB Output is correct
11 Correct 91 ms 235196 KB Output is correct
12 Correct 88 ms 235084 KB Output is correct
13 Correct 94 ms 235272 KB Output is correct
14 Correct 94 ms 235200 KB Output is correct
15 Correct 91 ms 235288 KB Output is correct
16 Correct 97 ms 235720 KB Output is correct
17 Correct 205 ms 239664 KB Output is correct
18 Correct 137 ms 237416 KB Output is correct
19 Correct 235 ms 248284 KB Output is correct
20 Correct 155 ms 236804 KB Output is correct
21 Correct 183 ms 246080 KB Output is correct
22 Correct 171 ms 237644 KB Output is correct
23 Correct 93 ms 235056 KB Output is correct
24 Correct 91 ms 235140 KB Output is correct
25 Correct 101 ms 238836 KB Output is correct
26 Correct 104 ms 235040 KB Output is correct
27 Correct 91 ms 235144 KB Output is correct
28 Correct 95 ms 235968 KB Output is correct
29 Correct 92 ms 235180 KB Output is correct
30 Runtime error 301 ms 262144 KB Execution killed with signal 9
31 Halted 0 ms 0 KB -