75182024-01-09 13:15:04adamElágazás nélküli úton levő települések (50 pont)cpp17Hibás válasz 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base25/50
1Elfogadva0/03ms1812 KiB
2Elfogadva0/030ms3876 KiB
3Hibás válasz0/23ms2260 KiB
4Hibás válasz0/23ms2636 KiB
5Elfogadva2/23ms2736 KiB
6Elfogadva2/23ms2820 KiB
7Elfogadva2/23ms2968 KiB
8Elfogadva2/24ms3092 KiB
9Elfogadva2/27ms3604 KiB
10Elfogadva2/29ms3916 KiB
11Elfogadva2/216ms4256 KiB
12Elfogadva2/217ms4384 KiB
13Hibás válasz0/34ms3824 KiB
14Futási hiba0/379ms63068 KiB
15Hibás válasz0/36ms4180 KiB
16Futási hiba0/375ms63040 KiB
17Hibás válasz0/314ms4860 KiB
18Hibás válasz0/314ms4984 KiB
19Hibás válasz0/317ms5484 KiB
20Elfogadva3/329ms6028 KiB
21Elfogadva3/332ms6336 KiB
22Elfogadva3/330ms6336 KiB