답안 #973993

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973993 2024-05-02T14:29:34 Z AtabayRajabli Monthly railway pass (LMIO18_menesinis_bilietas) C++17
100 / 100
557 ms 93044 KB
#include <bits/stdc++.h>
#define int ll
#define all(v) v.begin(), v.end()
 
// author : a1abay
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
const int sz = 5e5 + 5;
const int inf = 1e9 + 7;
 
int n, m, u, v, w;
int p[sz];
char c;
set<int> g[sz];

int par(int x)
{
    if(p[x] < 0) return x;
    return p[x] = par(p[x]);
}

bool join(int u, int v)
{
    u = par(u), v = par(v);
    if(u == v) return 0;
    if(p[u] > p[v]) swap(u, v);
    p[u] += p[v];
    p[v] = u;
    return 1;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    memset(p, -1, sizeof(p));
    cin >> n >> m;
    
    vector<array<int, 2>> e;
    for(int i = 1; i <= m; i++)
    {
        cin >> u >> v >> c;
        if(c == 'T') join(u, v);
        else e.push_back({u, v});
    }

    for(auto x : e)
    {
        u = x[0], v = x[1];
        u = par(u), v = par(v);
        if(par(u) != par(v))
        {
            g[u].insert(v);
            g[v].insert(u);
        }
    }
    set<int> s;
    for(int i = 1; i <= n; i++) s.insert(par(i));
    int cnt = 0;
    for(int i = 1; i <= n; i++) cnt += s.size() - 1 == g[par(i)].size();
    cout << cnt;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 27740 KB Output is correct
2 Correct 7 ms 27736 KB Output is correct
3 Correct 7 ms 27740 KB Output is correct
4 Correct 89 ms 49744 KB Output is correct
5 Correct 7 ms 28252 KB Output is correct
6 Correct 29 ms 27740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 49744 KB Output is correct
2 Correct 7 ms 28252 KB Output is correct
3 Correct 6 ms 27740 KB Output is correct
4 Correct 6 ms 27740 KB Output is correct
5 Correct 9 ms 28504 KB Output is correct
6 Correct 380 ms 67896 KB Output is correct
7 Correct 557 ms 93044 KB Output is correct
8 Correct 16 ms 30176 KB Output is correct
9 Correct 20 ms 31452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 27736 KB Output is correct
2 Correct 7 ms 27740 KB Output is correct
3 Correct 6 ms 27740 KB Output is correct
4 Correct 6 ms 27740 KB Output is correct
5 Correct 9 ms 28504 KB Output is correct
6 Correct 6 ms 27740 KB Output is correct
7 Correct 6 ms 27740 KB Output is correct
8 Correct 7 ms 27968 KB Output is correct
9 Correct 7 ms 27996 KB Output is correct
10 Correct 8 ms 28252 KB Output is correct
11 Correct 8 ms 27992 KB Output is correct
12 Correct 6 ms 27740 KB Output is correct
13 Correct 6 ms 27784 KB Output is correct
14 Correct 9 ms 28248 KB Output is correct
15 Correct 7 ms 27740 KB Output is correct
16 Correct 7 ms 27740 KB Output is correct
17 Correct 6 ms 27740 KB Output is correct
18 Correct 6 ms 27996 KB Output is correct
19 Correct 6 ms 27736 KB Output is correct
20 Correct 6 ms 27996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 27740 KB Output is correct
2 Correct 6 ms 27740 KB Output is correct
3 Correct 7 ms 27968 KB Output is correct
4 Correct 7 ms 27996 KB Output is correct
5 Correct 8 ms 28252 KB Output is correct
6 Correct 8 ms 27992 KB Output is correct
7 Correct 6 ms 27740 KB Output is correct
8 Correct 6 ms 27784 KB Output is correct
9 Correct 9 ms 28248 KB Output is correct
10 Correct 7 ms 27740 KB Output is correct
11 Correct 7 ms 27740 KB Output is correct
12 Correct 6 ms 27740 KB Output is correct
13 Correct 6 ms 27996 KB Output is correct
14 Correct 6 ms 27736 KB Output is correct
15 Correct 6 ms 27996 KB Output is correct
16 Correct 7 ms 27736 KB Output is correct
17 Correct 7 ms 27740 KB Output is correct
18 Correct 6 ms 27740 KB Output is correct
19 Correct 6 ms 27740 KB Output is correct
20 Correct 9 ms 28504 KB Output is correct
21 Correct 7 ms 28252 KB Output is correct
22 Correct 16 ms 30176 KB Output is correct
23 Correct 20 ms 31452 KB Output is correct
24 Correct 29 ms 27740 KB Output is correct
25 Correct 12 ms 28636 KB Output is correct
26 Correct 94 ms 40644 KB Output is correct
27 Correct 38 ms 33488 KB Output is correct
28 Correct 111 ms 44120 KB Output is correct
29 Correct 34 ms 31180 KB Output is correct
30 Correct 89 ms 41996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 27740 KB Output is correct
2 Correct 6 ms 27740 KB Output is correct
3 Correct 7 ms 27968 KB Output is correct
4 Correct 7 ms 27996 KB Output is correct
5 Correct 8 ms 28252 KB Output is correct
6 Correct 8 ms 27992 KB Output is correct
7 Correct 6 ms 27740 KB Output is correct
8 Correct 6 ms 27784 KB Output is correct
9 Correct 9 ms 28248 KB Output is correct
10 Correct 7 ms 27740 KB Output is correct
11 Correct 7 ms 27740 KB Output is correct
12 Correct 6 ms 27740 KB Output is correct
13 Correct 6 ms 27996 KB Output is correct
14 Correct 6 ms 27736 KB Output is correct
15 Correct 6 ms 27996 KB Output is correct
16 Correct 12 ms 28636 KB Output is correct
17 Correct 94 ms 40644 KB Output is correct
18 Correct 38 ms 33488 KB Output is correct
19 Correct 111 ms 44120 KB Output is correct
20 Correct 34 ms 31180 KB Output is correct
21 Correct 89 ms 41996 KB Output is correct
22 Correct 81 ms 27740 KB Output is correct
23 Correct 7 ms 27736 KB Output is correct
24 Correct 7 ms 27740 KB Output is correct
25 Correct 89 ms 49744 KB Output is correct
26 Correct 6 ms 27740 KB Output is correct
27 Correct 6 ms 27740 KB Output is correct
28 Correct 9 ms 28504 KB Output is correct
29 Correct 7 ms 28252 KB Output is correct
30 Correct 380 ms 67896 KB Output is correct
31 Correct 557 ms 93044 KB Output is correct
32 Correct 16 ms 30176 KB Output is correct
33 Correct 20 ms 31452 KB Output is correct
34 Correct 29 ms 27740 KB Output is correct
35 Correct 26 ms 30680 KB Output is correct
36 Correct 144 ms 45116 KB Output is correct
37 Correct 50 ms 30808 KB Output is correct