답안 #973988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973988 2024-05-02T14:23:57 Z AtabayRajabli Monthly railway pass (LMIO18_menesinis_bilietas) C++17
16 / 100
539 ms 97880 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);
        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 87 ms 33544 KB Output is correct
2 Correct 7 ms 27740 KB Output is correct
3 Correct 7 ms 27740 KB Output is correct
4 Correct 91 ms 49864 KB Output is correct
5 Correct 7 ms 28252 KB Output is correct
6 Correct 30 ms 30012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 49864 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 28528 KB Output is correct
6 Correct 373 ms 69904 KB Output is correct
7 Correct 539 ms 97880 KB Output is correct
8 Correct 15 ms 30176 KB Output is correct
9 Correct 21 ms 31964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 27740 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 28528 KB Output is correct
6 Correct 6 ms 27736 KB Output is correct
7 Correct 6 ms 27740 KB Output is correct
8 Correct 7 ms 27996 KB Output is correct
9 Correct 7 ms 27996 KB Output is correct
10 Incorrect 10 ms 28292 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 27736 KB Output is correct
2 Correct 6 ms 27740 KB Output is correct
3 Correct 7 ms 27996 KB Output is correct
4 Correct 7 ms 27996 KB Output is correct
5 Incorrect 10 ms 28292 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 27736 KB Output is correct
2 Correct 6 ms 27740 KB Output is correct
3 Correct 7 ms 27996 KB Output is correct
4 Correct 7 ms 27996 KB Output is correct
5 Incorrect 10 ms 28292 KB Output isn't correct
6 Halted 0 ms 0 KB -