Submission #921019

# Submission time Handle Problem Language Result Execution time Memory
921019 2024-02-03T08:58:05 Z gelastropod Monthly railway pass (LMIO18_menesinis_bilietas) C++14
16 / 100
574 ms 89284 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 && 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 514 ms 48312 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 18 ms 37208 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 118 ms 10168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 37208 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 5 ms 1372 KB Output is correct
6 Correct 300 ms 47028 KB Output is correct
7 Correct 574 ms 89284 KB Output is correct
8 Correct 14 ms 3540 KB Output is correct
9 Correct 20 ms 5592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 5 ms 1372 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 3 ms 608 KB Output is correct
10 Incorrect 5 ms 860 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Incorrect 5 ms 860 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Incorrect 5 ms 860 KB Output isn't correct
6 Halted 0 ms 0 KB -