답안 #676048

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676048 2022-12-29T07:42:47 Z Cookie Monthly railway pass (LMIO18_menesinis_bilietas) C++14
6 / 100
194 ms 38044 KB
#include<bits/stdc++.h>
 
#include<fstream>
 
using namespace std;
ifstream fin("talent.in");
ofstream fout("talent.out");
#define ll long long
#define vt vector
#define pb push_back
#define fi first
#define se second
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
//#define int long long
typedef unsigned long long ull;
const int mxn = 5e5 + 3;
int n, m;
vt<pii>edge;
vt<int>g[mxn + 1];
bool ok[mxn + 1], ans[mxn + 1];
struct DSU{
    int p[mxn + 1];
    void init(){
        for(int i = 1; i <= n; i++)p[i] = -1;
    }
    int fp(int a){
        if(p[a] < 0)return(a);
        return(p[a] = fp(p[a]));
    }
    void unon(int a, int b){
        a = fp(a); b = fp(b);
        if(a == b)return;
        if(-p[a] < -p[b])swap(a, b);
        p[a] += p[b]; p[b] = a;
        return;
    }
};
DSU dsu;
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    dsu.init();
    forr(i, 0, m){
        int u, v; cin >> u >> v;
        char c; cin >> c;
        if(c == 'A'){
            edge.pb({u, v});
        }else{
            dsu.unon(u, v);
        }
    }
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        if(dsu.p[i] < 0)cnt++;
    }
    
    for(auto [u, v]: edge){
        u = dsu.fp(u); v = dsu.fp(v);
        if(u != v){
            g[u].pb(v); g[v].pb(u);
        }
        //cout << u << ' ' << v << " ";
    }
    for(int i = 1; i <= n; i++){
        if(g[i].size()){
            int curr  =0;
            for(auto j: g[i]){
                if(!ok[j]){
                    ok[j] = true; curr++;
                }
            }
            ans[i] = ((curr + 1) == cnt);
            for(auto j: g[i])ok[j] = false;
        }
    }
   
    int res  =0;
    for(int i = 1; i <= n; i++){
        res += ans[dsu.fp(i)];
    }
    cout << res;
    return 0;
}

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:61:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   61 |     for(auto [u, v]: edge){
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 113 ms 20128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 13908 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 6 ms 12116 KB Output is correct
4 Correct 7 ms 12244 KB Output is correct
5 Correct 6 ms 12080 KB Output is correct
6 Correct 88 ms 23352 KB Output is correct
7 Correct 194 ms 38044 KB Output is correct
8 Correct 10 ms 13012 KB Output is correct
9 Correct 14 ms 13296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 12116 KB Output is correct
3 Correct 7 ms 12244 KB Output is correct
4 Correct 6 ms 11988 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 6 ms 12092 KB Output is correct
7 Correct 7 ms 12224 KB Output is correct
8 Correct 8 ms 12352 KB Output is correct
9 Correct 7 ms 12244 KB Output is correct
10 Correct 6 ms 11988 KB Output is correct
11 Correct 6 ms 12084 KB Output is correct
12 Correct 8 ms 12372 KB Output is correct
13 Incorrect 7 ms 12068 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 6 ms 12092 KB Output is correct
4 Correct 7 ms 12224 KB Output is correct
5 Correct 8 ms 12352 KB Output is correct
6 Correct 7 ms 12244 KB Output is correct
7 Correct 6 ms 11988 KB Output is correct
8 Correct 6 ms 12084 KB Output is correct
9 Correct 8 ms 12372 KB Output is correct
10 Incorrect 7 ms 12068 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 6 ms 12092 KB Output is correct
4 Correct 7 ms 12224 KB Output is correct
5 Correct 8 ms 12352 KB Output is correct
6 Correct 7 ms 12244 KB Output is correct
7 Correct 6 ms 11988 KB Output is correct
8 Correct 6 ms 12084 KB Output is correct
9 Correct 8 ms 12372 KB Output is correct
10 Incorrect 7 ms 12068 KB Output isn't correct
11 Halted 0 ms 0 KB -