230502026-01-16 11:18:14MrkzElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 4/5028ms1332 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> graf(N + 1);
    vector<int> fokszam(N + 1, 0);
    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        graf[a].push_back(b);
        graf[b].push_back(a);
        fokszam[a]++;
        fokszam[b]++;
    }

    vector<bool> visited(N + 1, false);
    vector<int> result;
    for (int i = 1; i <= N; i++)
    {
        if (fokszam[i] == 1 && !visited[i])
        {
            int current = i;
            int prev = -1;
            while (true)
            {
                visited[current] = true;
                int next = -1;
                for (int neigh : graf[current])
                {
                    if (neigh != prev)
                    {
                        next = neigh;
                        break;
                    }
                }
                if (next == -1)
                    break;
                prev = current;
                current = next;
                if (current != i)
                    result.push_back(current);
                if (fokszam[current] > 2)
                    break;
            }
        }
    }
    cout << result.size() << endl;
    for (int node : result)
    {
        cout << node << " ";
    }
    cout << endl;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base4/50
1Accepted0/01ms316 KiB
2Wrong answer0/027ms1332 KiB
3Wrong answer0/21ms316 KiB
4Wrong answer0/21ms316 KiB
5Accepted2/21ms316 KiB
6Wrong answer0/21ms404 KiB
7Wrong answer0/21ms316 KiB
8Wrong answer0/23ms316 KiB
9Wrong answer0/24ms564 KiB
10Wrong answer0/27ms624 KiB
11Accepted2/214ms772 KiB
12Wrong answer0/214ms900 KiB
13Wrong answer0/32ms508 KiB
14Wrong answer0/33ms508 KiB
15Wrong answer0/34ms564 KiB
16Wrong answer0/34ms580 KiB
17Wrong answer0/312ms816 KiB
18Wrong answer0/313ms840 KiB
19Wrong answer0/316ms1052 KiB
20Wrong answer0/326ms1324 KiB
21Wrong answer0/328ms1288 KiB
22Wrong answer0/327ms1332 KiB