Submission #921020

# Submission time Handle Problem Language Result Execution time Memory
921020 2024-02-03T08:58:38 Z gelastropod Monthly railway pass (LMIO18_menesinis_bilietas) C++14
100 / 100
521 ms 90292 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

int nSets;
vector<int> dsu;
int find(int x)
{
    if (dsu[x] == x) return x;
    return dsu[x] = find(dsu[x]);
}

void join(int a, int b)
{
    a = find(a), b = find(b);
    if (a == b) return;
    dsu[a] = b;
    nSets--;
}

signed main()
{
    int N, M, a, b, ans = 0;
    cin >> N >> M;
    char t;
    for (int i = 0; i < N; i++) dsu.push_back(i);
    nSets = N;
    vector<vector<pair<int, bool>>> adjlist(N, vector<pair<int, bool>>());
    for (int i = 0; i < M; i++)
    {
        cin >> a >> b >> t;
        a--, b--;
        adjlist[a].push_back(pair<int, int>(b, t == 'A'));
        adjlist[b].push_back(pair<int, int>(a, t == 'A'));
        if (t == 'T') join(a, b);
    }
    vector<set<int>> btradjlist(N, set<int>());
    for (int i = 0; i < N; i++)
    {
        for (auto j : adjlist[i])
        {
            if (j.second && find(i) != find(j.first))
                btradjlist[find(i)].insert(find(j.first));
        }
    }
    for (int i = 0; i < N; i++)
    {
        if (btradjlist[find(i)].size() == nSets - 1) ans++;
    }
    cout << ans << '\n';
}

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:48:40: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   48 |         if (btradjlist[find(i)].size() == nSets - 1) ans++;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 431 ms 48116 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 20 ms 37320 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 110 ms 10396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 37320 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 316 ms 46944 KB Output is correct
7 Correct 521 ms 90292 KB Output is correct
8 Correct 11 ms 3544 KB Output is correct
9 Correct 21 ms 5548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 3 ms 616 KB Output is correct
10 Correct 5 ms 992 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 6 ms 1168 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 360 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 3 ms 616 KB Output is correct
5 Correct 5 ms 992 KB Output is correct
6 Correct 4 ms 860 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 6 ms 1168 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 4 ms 1372 KB Output is correct
21 Correct 1 ms 1372 KB Output is correct
22 Correct 11 ms 3544 KB Output is correct
23 Correct 21 ms 5548 KB Output is correct
24 Correct 110 ms 10396 KB Output is correct
25 Correct 14 ms 2236 KB Output is correct
26 Correct 207 ms 20272 KB Output is correct
27 Correct 66 ms 7856 KB Output is correct
28 Correct 118 ms 20308 KB Output is correct
29 Correct 52 ms 6484 KB Output is correct
30 Correct 130 ms 19200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 360 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 3 ms 616 KB Output is correct
5 Correct 5 ms 992 KB Output is correct
6 Correct 4 ms 860 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 6 ms 1168 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 14 ms 2236 KB Output is correct
17 Correct 207 ms 20272 KB Output is correct
18 Correct 66 ms 7856 KB Output is correct
19 Correct 118 ms 20308 KB Output is correct
20 Correct 52 ms 6484 KB Output is correct
21 Correct 130 ms 19200 KB Output is correct
22 Correct 431 ms 48116 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 20 ms 37320 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 4 ms 1372 KB Output is correct
29 Correct 1 ms 1372 KB Output is correct
30 Correct 316 ms 46944 KB Output is correct
31 Correct 521 ms 90292 KB Output is correct
32 Correct 11 ms 3544 KB Output is correct
33 Correct 21 ms 5548 KB Output is correct
34 Correct 110 ms 10396 KB Output is correct
35 Correct 47 ms 7116 KB Output is correct
36 Correct 383 ms 32456 KB Output is correct
37 Correct 192 ms 26812 KB Output is correct