답안 #920874

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920874 2024-02-03T07:04:26 Z gelastropod Monthly railway pass (LMIO18_menesinis_bilietas) C++14
6 / 100
404 ms 32884 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
    int N, M, a, b, ans = 0;
    cin >> N >> M;
    char t;
    bool is1 = true, is2 = true;
    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 == 'A') is1 = false;
        if (t == 'T') is2 = false;
    }
    queue<int> bfs;
    vector<bool> visited(N, false);
    bfs.push(0);
    visited[0] = true;
    while (!bfs.empty())
    {
        int i = bfs.front();
        bfs.pop();
        for (auto j : adjlist[i])
            if (!visited[j.first])
                visited[j.first] = true, bfs.push(j.first);
    }
    if (is1)
    {
        bool can = true;
        for (int i = 0; i < N; i++)
        {
            if (!visited[i])
                can = false;
        }
        cout << (can == N ? N : 0) << '\n';
        return 0;
    }
    else if (is2)
    {
        for (int i = 0; i < N; i++)
        {
            if ((int)adjlist[i].size() >= N - 1)
                ans++;
        }
        cout << ans << '\n';
        return 0;
    }
    queue<pair<int, bool>> bfs1;
    vector<pair<int, int>> visited1;
    bool can;
    for (int i = 0; i < N; i++)
    {
        visited1 = vector<pair<int, int>>(N, pair<int, int>(false, false));
        bfs1.push(pair<int, bool>(i, false));
        visited1[i].first = true;
        while (!bfs1.empty())
        {
            auto j = bfs1.front();
            bfs1.pop();
            for (auto k : adjlist[j.first])
            {
                if (!j.second && !k.second)
                {
                    if (!visited1[k.first].first)
                        visited1[k.first].first = true, bfs1.push(pair<int, int>(k.first, false));
                }
                if ((!j.second && k.second) || (j.second && !k.second))
                {
                    if (!visited1[k.first].second)
                        visited1[k.first].second = true, bfs1.push(pair<int, int>(k.first, true));
                }
            }
        }
        can = true;
        for (int i = 0; i < N; i++)
        {
            if (!(visited1[i].first || visited1[i].second))
                can = false;
        }
        if (can)
            ans++;
    }
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 404 ms 31976 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 11352 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 168 ms 14376 KB Output is correct
7 Correct 284 ms 32884 KB Output is correct
8 Correct 8 ms 1492 KB Output is correct
9 Correct 14 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 10 ms 604 KB Output is correct
8 Correct 23 ms 860 KB Output is correct
9 Correct 8 ms 604 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 20 ms 1116 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 21 ms 604 KB Output is correct
19 Incorrect 0 ms 348 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 10 ms 604 KB Output is correct
5 Correct 23 ms 860 KB Output is correct
6 Correct 8 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 20 ms 1116 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 21 ms 604 KB Output is correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 10 ms 604 KB Output is correct
5 Correct 23 ms 860 KB Output is correct
6 Correct 8 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 20 ms 1116 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 21 ms 604 KB Output is correct
16 Incorrect 404 ms 31976 KB Output isn't correct
17 Halted 0 ms 0 KB -