Submission #920875

# Submission time Handle Problem Language Result Execution time Memory
920875 2024-02-03T07:05:17 Z gelastropod Monthly railway pass (LMIO18_menesinis_bilietas) C++14
46 / 100
3000 ms 32332 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 : 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';
}
# Verdict Execution time Memory Grader output
1 Correct 429 ms 31928 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 3 ms 11356 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 89 ms 9892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11356 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 169 ms 14336 KB Output is correct
7 Correct 264 ms 32332 KB Output is correct
8 Correct 8 ms 1492 KB Output is correct
9 Correct 18 ms 2224 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 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 1 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 10 ms 748 KB Output is correct
10 Correct 23 ms 860 KB Output is correct
11 Correct 8 ms 604 KB Output is correct
12 Correct 1 ms 432 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 15 ms 1092 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 17 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 748 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 432 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 15 ms 1092 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 3 ms 344 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 17 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 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 3 ms 600 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 8 ms 1492 KB Output is correct
23 Correct 18 ms 2224 KB Output is correct
24 Correct 89 ms 9892 KB Output is correct
25 Correct 107 ms 2140 KB Output is correct
26 Execution timed out 3045 ms 20140 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 748 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 432 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 15 ms 1092 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 3 ms 344 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 17 ms 604 KB Output is correct
16 Correct 107 ms 2140 KB Output is correct
17 Execution timed out 3045 ms 20140 KB Time limit exceeded
18 Halted 0 ms 0 KB -