Submission #362430

# Submission time Handle Problem Language Result Execution time Memory
362430 2021-02-03T07:42:54 Z _martynas Monthly railway pass (LMIO18_menesinis_bilietas) C++11
100 / 100
802 ms 87620 KB
#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;
const int MAX_N = 5e5+5;
#define PB push_back

vi A[MAX_N];
vi T[MAX_N];
vector<vi> Groups;
int Group[MAX_N];
int group;
bool visited[MAX_N];

int n, m;

void dfs(int curr)
{
    visited[curr] = true;
    Group[curr] = group;
    Groups[group].PB(curr);

    for(int x : T[curr])
    {
        if(!visited[x])
        {
            dfs(x);
        }
    }
}

int main()
{
    //freopen("lmio_2018_3e2_menesinis_bilietas_vyr.in", "r", stdin);
    //freopen("lmio_2018_3e2_menesinis_bilietas_vyr.out", "w", stdout);

    scanf("%d%d", &n, &m);

    for(int i = 0; i < m; i++)
    {
        int a, b;
        char c;
        scanf("%d%d %c", &a, &b, &c);
        a--;
        b--;
        if(c == 'A')
        {
            A[a].PB(b);
            A[b].PB(a);
        }
        else
        {
            T[a].PB(b);
            T[b].PB(a);
        }
    }

    group = 0;

    for(int i = 0; i < n; i++)
    {
        if(!visited[i])
        {
            Groups.PB(vi());
            dfs(i);
            group++;
        }
    }

    int ans = 0;
    set<int> OtherGroups;

    for(vi &g : Groups)
    {
        for(int x : g)
        {
            for(int v : A[x])
            {
                if(Group[v] != Group[x])
                    OtherGroups.insert(Group[v]);
            }
        }
        if(OtherGroups.size() == group - 1)
        {
            ans += g.size();
        }
        OtherGroups.clear();
    }

    printf("%d", ans);

    return 0;
}

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:84:31: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   84 |         if(OtherGroups.size() == group - 1)
      |            ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
menesinis_bilietas.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
menesinis_bilietas.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |         scanf("%d%d %c", &a, &b, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 453 ms 51808 KB Output is correct
2 Correct 17 ms 23788 KB Output is correct
3 Correct 17 ms 23788 KB Output is correct
4 Correct 68 ms 51852 KB Output is correct
5 Correct 18 ms 24616 KB Output is correct
6 Correct 84 ms 29292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 51852 KB Output is correct
2 Correct 18 ms 24616 KB Output is correct
3 Correct 16 ms 23788 KB Output is correct
4 Correct 17 ms 23788 KB Output is correct
5 Correct 21 ms 24044 KB Output is correct
6 Correct 291 ms 37000 KB Output is correct
7 Correct 802 ms 87620 KB Output is correct
8 Correct 34 ms 26152 KB Output is correct
9 Correct 35 ms 26408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 17 ms 23788 KB Output is correct
3 Correct 16 ms 23788 KB Output is correct
4 Correct 17 ms 23788 KB Output is correct
5 Correct 21 ms 24044 KB Output is correct
6 Correct 17 ms 23788 KB Output is correct
7 Correct 16 ms 23916 KB Output is correct
8 Correct 18 ms 23916 KB Output is correct
9 Correct 19 ms 23916 KB Output is correct
10 Correct 23 ms 24044 KB Output is correct
11 Correct 19 ms 23916 KB Output is correct
12 Correct 17 ms 23788 KB Output is correct
13 Correct 17 ms 23808 KB Output is correct
14 Correct 22 ms 24172 KB Output is correct
15 Correct 17 ms 23788 KB Output is correct
16 Correct 18 ms 23916 KB Output is correct
17 Correct 18 ms 23788 KB Output is correct
18 Correct 18 ms 23916 KB Output is correct
19 Correct 17 ms 23916 KB Output is correct
20 Correct 18 ms 23916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 16 ms 23916 KB Output is correct
3 Correct 18 ms 23916 KB Output is correct
4 Correct 19 ms 23916 KB Output is correct
5 Correct 23 ms 24044 KB Output is correct
6 Correct 19 ms 23916 KB Output is correct
7 Correct 17 ms 23788 KB Output is correct
8 Correct 17 ms 23808 KB Output is correct
9 Correct 22 ms 24172 KB Output is correct
10 Correct 17 ms 23788 KB Output is correct
11 Correct 18 ms 23916 KB Output is correct
12 Correct 18 ms 23788 KB Output is correct
13 Correct 18 ms 23916 KB Output is correct
14 Correct 17 ms 23916 KB Output is correct
15 Correct 18 ms 23916 KB Output is correct
16 Correct 17 ms 23788 KB Output is correct
17 Correct 17 ms 23788 KB Output is correct
18 Correct 16 ms 23788 KB Output is correct
19 Correct 17 ms 23788 KB Output is correct
20 Correct 21 ms 24044 KB Output is correct
21 Correct 18 ms 24616 KB Output is correct
22 Correct 34 ms 26152 KB Output is correct
23 Correct 35 ms 26408 KB Output is correct
24 Correct 84 ms 29292 KB Output is correct
25 Correct 28 ms 24704 KB Output is correct
26 Correct 205 ms 33916 KB Output is correct
27 Correct 76 ms 27500 KB Output is correct
28 Correct 118 ms 28652 KB Output is correct
29 Correct 69 ms 26604 KB Output is correct
30 Correct 122 ms 28948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 16 ms 23916 KB Output is correct
3 Correct 18 ms 23916 KB Output is correct
4 Correct 19 ms 23916 KB Output is correct
5 Correct 23 ms 24044 KB Output is correct
6 Correct 19 ms 23916 KB Output is correct
7 Correct 17 ms 23788 KB Output is correct
8 Correct 17 ms 23808 KB Output is correct
9 Correct 22 ms 24172 KB Output is correct
10 Correct 17 ms 23788 KB Output is correct
11 Correct 18 ms 23916 KB Output is correct
12 Correct 18 ms 23788 KB Output is correct
13 Correct 18 ms 23916 KB Output is correct
14 Correct 17 ms 23916 KB Output is correct
15 Correct 18 ms 23916 KB Output is correct
16 Correct 28 ms 24704 KB Output is correct
17 Correct 205 ms 33916 KB Output is correct
18 Correct 76 ms 27500 KB Output is correct
19 Correct 118 ms 28652 KB Output is correct
20 Correct 69 ms 26604 KB Output is correct
21 Correct 122 ms 28948 KB Output is correct
22 Correct 453 ms 51808 KB Output is correct
23 Correct 17 ms 23788 KB Output is correct
24 Correct 17 ms 23788 KB Output is correct
25 Correct 68 ms 51852 KB Output is correct
26 Correct 16 ms 23788 KB Output is correct
27 Correct 17 ms 23788 KB Output is correct
28 Correct 21 ms 24044 KB Output is correct
29 Correct 18 ms 24616 KB Output is correct
30 Correct 291 ms 37000 KB Output is correct
31 Correct 802 ms 87620 KB Output is correct
32 Correct 34 ms 26152 KB Output is correct
33 Correct 35 ms 26408 KB Output is correct
34 Correct 84 ms 29292 KB Output is correct
35 Correct 59 ms 26732 KB Output is correct
36 Correct 392 ms 39148 KB Output is correct
37 Correct 213 ms 35564 KB Output is correct