Submission #805685

# Submission time Handle Problem Language Result Execution time Memory
805685 2023-08-03T20:22:23 Z HD1 Monthly railway pass (LMIO18_menesinis_bilietas) C++14
0 / 100
275 ms 3924 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) int(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;
ll p[MAX];
ll fiend(ll u){
    if(p[u]==u)return u;
    return p[u]=fiend(p[u]);
}
void unir(ll u, ll v){
    ll x=fiend(u);
    ll y=fiend(v);
    if(x!=y){
        p[max(x,y)]=min(y,x);
    }
    return;
}
void solve(){
    ll n, m, u, v;
    char x;
    cin>>n>>m;
    for(ll i=0; i<=n; i++) p[i]=i;
    for(ll i=0; i<m; i++){
        cin>>u>>v>>x;
        fiend(u);
        fiend(v);
        if(p[u]!=p[v]){
            unir(u,v);
        }
    }
    bool nice=true;
    for(ll i=1; i<=n; i++){
        if(p[i]!=p[1]){
            nice=false;
            break;
        }
    }
    if(nice)cout<<n<<endl;
    else cout<<0<<endl;
    return;
}
int main(){
    solve();
    return 0;
}
/* 
5 4
1 2 A
2 5 A
3 4 A
1 5 A
*/
# Verdict Execution time Memory Grader output
1 Incorrect 275 ms 2612 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3924 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 275 ms 2612 KB Output isn't correct
2 Halted 0 ms 0 KB -