Submission #805722

# Submission time Handle Problem Language Result Execution time Memory
805722 2023-08-03T21:30:51 Z HD1 Monthly railway pass (LMIO18_menesinis_bilietas) C++14
100 / 100
738 ms 101532 KB
// we all are lost trying to be someone.
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_studio(0); cin.tie(0);
#define sz(x) ll(x.size())
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
#define ss second
#define ff first
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
const int MAX=1e6;
const int inf=1e9;
const int mod=1e9+7;
vector<ll> gfo1[MAX];
vector<ll> gfo2[MAX];
vector<ii> s;
vector<ll> c;
bool vst[MAX];
ll tam[MAX], p[MAX];
set<ii> z;
void dfsmark(ll u, ll x){
    p[u]=x;
    tam[x]++;
    vst[u]=true;
    for(ll v:gfo1[u]){
        if(!vst[v]){
            dfsmark(v,x);
        }
    }
}
void solve(){
    ll n, m, u, v;
    char x;
    cin>>n>>m;
    for(ll i=0; i<m; i++){
        cin>>u>>v>>x;
        if(x=='A'){
            s.pb({u,v});
        }
        else{
            gfo1[u].pb(v);
            gfo1[v].pb(u);        
        }
    }
    ll cont=1;
    for(ll i=1; i<=n; i++){
        if(!vst[i]) {
            dfsmark(i,cont);
            cont++;
        }
    }
    cont--;
    if(cont==1){
        cout<<n<<endl;
        return;
    }
    //cout<<cont<<endl;
    for(ii x:s){
        u=p[x.ff];
        v=p[x.ss];
        if(u!=v && !(z.count({min(u,v),max(u,v)}))){
            gfo2[u].pb(v);
            gfo2[v].pb(u);
            z.insert({min(u,v),max(u,v)});
        }
    }
    ll ans=0;
    /*for(ll i=1; i<=n; i++){
        cout<<i<<"-> p: "<<p[i]<<endl;     
    }
    cout<<endl;
    for(ll i=1; i<=cont; i++){
        cout<<i<<": ";
        for(ll v:gfo2[i]){
            cout<<v<<" ";
        }
        cout<<endl;
    }*/
    for(ll i=1; i<=cont; i++){
        if(sz(gfo2[i])==cont-1)ans+=tam[i];
    }
    cout<<ans<<endl;  
    return;
}
int main(){
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 387 ms 71720 KB Output is correct
2 Correct 20 ms 47188 KB Output is correct
3 Correct 22 ms 47316 KB Output is correct
4 Correct 26 ms 55068 KB Output is correct
5 Correct 22 ms 47420 KB Output is correct
6 Correct 107 ms 52440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 55068 KB Output is correct
2 Correct 22 ms 47420 KB Output is correct
3 Correct 20 ms 47268 KB Output is correct
4 Correct 21 ms 47368 KB Output is correct
5 Correct 25 ms 48044 KB Output is correct
6 Correct 423 ms 82320 KB Output is correct
7 Correct 738 ms 101532 KB Output is correct
8 Correct 34 ms 49272 KB Output is correct
9 Correct 44 ms 50460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47188 KB Output is correct
2 Correct 22 ms 47316 KB Output is correct
3 Correct 20 ms 47268 KB Output is correct
4 Correct 21 ms 47368 KB Output is correct
5 Correct 25 ms 48044 KB Output is correct
6 Correct 20 ms 47272 KB Output is correct
7 Correct 21 ms 47284 KB Output is correct
8 Correct 21 ms 47316 KB Output is correct
9 Correct 22 ms 47444 KB Output is correct
10 Correct 26 ms 47556 KB Output is correct
11 Correct 23 ms 47572 KB Output is correct
12 Correct 21 ms 47312 KB Output is correct
13 Correct 20 ms 47316 KB Output is correct
14 Correct 31 ms 47640 KB Output is correct
15 Correct 20 ms 47252 KB Output is correct
16 Correct 22 ms 47316 KB Output is correct
17 Correct 24 ms 47180 KB Output is correct
18 Correct 21 ms 47316 KB Output is correct
19 Correct 21 ms 47316 KB Output is correct
20 Correct 22 ms 47444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47272 KB Output is correct
2 Correct 21 ms 47284 KB Output is correct
3 Correct 21 ms 47316 KB Output is correct
4 Correct 22 ms 47444 KB Output is correct
5 Correct 26 ms 47556 KB Output is correct
6 Correct 23 ms 47572 KB Output is correct
7 Correct 21 ms 47312 KB Output is correct
8 Correct 20 ms 47316 KB Output is correct
9 Correct 31 ms 47640 KB Output is correct
10 Correct 20 ms 47252 KB Output is correct
11 Correct 22 ms 47316 KB Output is correct
12 Correct 24 ms 47180 KB Output is correct
13 Correct 21 ms 47316 KB Output is correct
14 Correct 21 ms 47316 KB Output is correct
15 Correct 22 ms 47444 KB Output is correct
16 Correct 20 ms 47188 KB Output is correct
17 Correct 22 ms 47316 KB Output is correct
18 Correct 20 ms 47268 KB Output is correct
19 Correct 21 ms 47368 KB Output is correct
20 Correct 25 ms 48044 KB Output is correct
21 Correct 22 ms 47420 KB Output is correct
22 Correct 34 ms 49272 KB Output is correct
23 Correct 44 ms 50460 KB Output is correct
24 Correct 107 ms 52440 KB Output is correct
25 Correct 34 ms 47868 KB Output is correct
26 Correct 216 ms 56160 KB Output is correct
27 Correct 85 ms 51476 KB Output is correct
28 Correct 159 ms 60148 KB Output is correct
29 Correct 72 ms 49664 KB Output is correct
30 Correct 152 ms 59000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47272 KB Output is correct
2 Correct 21 ms 47284 KB Output is correct
3 Correct 21 ms 47316 KB Output is correct
4 Correct 22 ms 47444 KB Output is correct
5 Correct 26 ms 47556 KB Output is correct
6 Correct 23 ms 47572 KB Output is correct
7 Correct 21 ms 47312 KB Output is correct
8 Correct 20 ms 47316 KB Output is correct
9 Correct 31 ms 47640 KB Output is correct
10 Correct 20 ms 47252 KB Output is correct
11 Correct 22 ms 47316 KB Output is correct
12 Correct 24 ms 47180 KB Output is correct
13 Correct 21 ms 47316 KB Output is correct
14 Correct 21 ms 47316 KB Output is correct
15 Correct 22 ms 47444 KB Output is correct
16 Correct 34 ms 47868 KB Output is correct
17 Correct 216 ms 56160 KB Output is correct
18 Correct 85 ms 51476 KB Output is correct
19 Correct 159 ms 60148 KB Output is correct
20 Correct 72 ms 49664 KB Output is correct
21 Correct 152 ms 59000 KB Output is correct
22 Correct 387 ms 71720 KB Output is correct
23 Correct 20 ms 47188 KB Output is correct
24 Correct 22 ms 47316 KB Output is correct
25 Correct 26 ms 55068 KB Output is correct
26 Correct 20 ms 47268 KB Output is correct
27 Correct 21 ms 47368 KB Output is correct
28 Correct 25 ms 48044 KB Output is correct
29 Correct 22 ms 47420 KB Output is correct
30 Correct 423 ms 82320 KB Output is correct
31 Correct 738 ms 101532 KB Output is correct
32 Correct 34 ms 49272 KB Output is correct
33 Correct 44 ms 50460 KB Output is correct
34 Correct 107 ms 52440 KB Output is correct
35 Correct 71 ms 50344 KB Output is correct
36 Correct 298 ms 60640 KB Output is correct
37 Correct 178 ms 55540 KB Output is correct