65302023-12-07 10:31:21tamasmarkElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 6/5029ms6664 KiB
// zsakfalvak.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <deque>
#include <vector>

using namespace std;

struct adat
{
    int lep, lat;
    vector<int>sz;
};
deque<adat>x;
int akt;
deque<int>v,y,megold,megoldb;

int n, a, b, i, kezd,m;

int main()
{
    cin >> n>>m;
    x.resize(n + 1);
    megoldb.resize(n + 1);
    for (i = 1; i <= m; ++i)
    {
        cin >> a >> b;
        x[a].sz.push_back(b);
        x[b].sz.push_back(a);
    }
    for (i = 1; i <= n; ++i)
        if (x[i].sz.size() == 1)
        {
            y.push_back(i);
        }
    i = 0;
    while (!y.empty())
    {
        i++;
        v.push_back(y.front());
        //y.pop_front();
        x[v.front()].lat = i;
        while (!v.empty())
        {
           akt = v.front();
           v.pop_front();
           for (auto& e : x[akt].sz)
           {
               if (x[e].sz.size() <= 2 &&x[e].lat<x[akt].lat)
               {
                   x[e].lat = x[akt].lat;
                   v.push_back(e);
                   if (!megoldb[e]) megold.push_back(e);
                   megoldb[e] = 1;
               }
               else if (x[akt].sz.size() <= 2 && x[e].lat < x[akt].lat)
               {
                   if (!megoldb[e]) megold.push_back(e);
                   megoldb[e]=1;
                   x[e].lat = x[akt].lat;
               }
           }
        }
        y.pop_front();
    }
    cout << megold.size()<<"\n";
    for (i = 0; i <megold.size();++i) cout << megold[i] << " ";
    return 0;
}
/*
8 9
1 2
1 6
2 7
1 5
3 4
4 5
5 6
6 7
8 7
*/
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base6/50
1Accepted0/03ms1816 KiB
2Wrong answer0/029ms4268 KiB
3Wrong answer0/23ms2120 KiB
4Accepted2/23ms2320 KiB
5Accepted2/23ms2588 KiB
6Wrong answer0/23ms2556 KiB
7Wrong answer0/23ms2684 KiB
8Wrong answer0/24ms3144 KiB
9Wrong answer0/26ms3288 KiB
10Wrong answer0/28ms3808 KiB
11Accepted2/216ms4280 KiB
12Wrong answer0/216ms4536 KiB
13Wrong answer0/34ms3736 KiB
14Wrong answer0/34ms3900 KiB
15Wrong answer0/36ms3960 KiB
16Wrong answer0/37ms4204 KiB
17Wrong answer0/314ms4956 KiB
18Wrong answer0/314ms5320 KiB
19Wrong answer0/317ms5668 KiB
20Wrong answer0/328ms6164 KiB
21Wrong answer0/329ms6584 KiB
22Wrong answer0/329ms6664 KiB