답안 #362429

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
362429 2021-02-03T07:42:06 Z _martynas Monthly railway pass (LMIO18_menesinis_bilietas) C++11
0 / 100
19 ms 23916 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:35:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   35 |     freopen("lmio_2018_3e2_menesinis_bilietas_vyr.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
menesinis_bilietas.cpp:36:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   36 |     freopen("lmio_2018_3e2_menesinis_bilietas_vyr.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 23788 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 23788 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 23916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 23916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 23916 KB Output isn't correct
2 Halted 0 ms 0 KB -