75182024-01-09 13:15:04adamElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 25/5079ms63068 KiB
#include <bits/stdc++.h>
using namespace std;
int main()
{

    int village_count = 0;
    int road_count = 0;
    cin >> village_count;
    cin >> road_count;
    vector<vector<int>> village_tree(village_count, vector<int>(0, 0));
    for (int i = 0; i < road_count; i++)
    {
        int village_id = 0;
        int village_to = 0;

        cin >> village_id;
        cin >> village_to;
        village_tree[village_id - 1].push_back(village_to - 1);
        village_tree[village_to - 1].push_back(village_id - 1);
    }
    vector<int> accessible(0, 0);

    for (int i = 0; i < village_count; i++)
    {
        if (village_tree[i].size() != 1)
            continue;
        bool ended = false;
        int previous = i;
        int check = village_tree[i][0];

        while (!ended)
        {
            accessible.push_back(check);
            if (village_tree[check].size() > 2)
            {

                ended = true;
            }
            else
            {
                if (village_tree[check].size() == 1)
                    ended = true;
                else if (village_tree[check][0] == previous)
                    check = village_tree[check][1];
                else
                    check = village_tree[check][0];
                previous = check;
            }
        }
    }
    sort(accessible.begin(), accessible.end());

    cout << accessible.size() << "\n";
    for (int v : accessible)
    {
        cout << v+1 << " ";
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base25/50
1Accepted0/03ms1812 KiB
2Accepted0/030ms3876 KiB
3Wrong answer0/23ms2260 KiB
4Wrong answer0/23ms2636 KiB
5Accepted2/23ms2736 KiB
6Accepted2/23ms2820 KiB
7Accepted2/23ms2968 KiB
8Accepted2/24ms3092 KiB
9Accepted2/27ms3604 KiB
10Accepted2/29ms3916 KiB
11Accepted2/216ms4256 KiB
12Accepted2/217ms4384 KiB
13Wrong answer0/34ms3824 KiB
14Runtime error0/379ms63068 KiB
15Wrong answer0/36ms4180 KiB
16Runtime error0/375ms63040 KiB
17Wrong answer0/314ms4860 KiB
18Wrong answer0/314ms4984 KiB
19Wrong answer0/317ms5484 KiB
20Accepted3/329ms6028 KiB
21Accepted3/332ms6336 KiB
22Accepted3/330ms6336 KiB