57872023-09-29 09:47:40zsebiElágazás nélküli úton levő települések (50 pont)cpp11Wrong answer 25/5030ms7008 KiB
// elagazas nelkul.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>
#include <algorithm>

#define ll long long 
using namespace std;

struct adat
{
   
    vector<ll>sz;
};
ll n, m;

int main()
{
    cin >> n >> m;
    vector<adat>x(n+1);
    vector<ll>ans;
    for (int i = 1; i <= m; ++i)
    {
        ll a, b;
        cin >> a >> b;
        x[a].sz.push_back(b);
        x[b].sz.push_back(a);
    }
    vector<ll>falu;
    for (int i = 1; i <= n; ++i)
    {
        if (x[i].sz.size() == 1)falu.push_back(i);
    }
    for (auto b:falu)
    {
            deque<ll>v;
            v.push_back(b);
            vector<ll>lat(n+1,0);
            lat[b] = 1;
            while (!v.empty())
            {
                ll akt = v.front();
               
                v.pop_front();
               
                for (auto& e : x[akt].sz)
                {
                    
                    if (!lat[e])
                    {
                        lat[e] = 1;
                        ans.push_back(e);
                        if (x[e].sz.size() > 2)break;
                            v.push_back(e);
                    }
                }

            }
      
    }
    if (!ans.empty())
    {
        sort(ans.begin(), ans.end());
        cout << ans.size() << "\n";
        for (auto& e : ans)cout << e << " ";
    }
    else cout << "0";

    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
base25/50
1Accepted0/03ms1684 KiB
2Accepted0/029ms4840 KiB
3Wrong answer0/22ms2136 KiB
4Wrong answer0/23ms2404 KiB
5Accepted2/22ms2368 KiB
6Accepted2/22ms2624 KiB
7Accepted2/22ms2648 KiB
8Accepted2/24ms3020 KiB
9Accepted2/26ms3524 KiB
10Accepted2/28ms4068 KiB
11Accepted2/216ms4912 KiB
12Accepted2/216ms5280 KiB
13Wrong answer0/34ms3932 KiB
14Wrong answer0/34ms4068 KiB
15Wrong answer0/36ms4308 KiB
16Wrong answer0/38ms4680 KiB
17Wrong answer0/314ms5396 KiB
18Wrong answer0/316ms5608 KiB
19Wrong answer0/318ms6000 KiB
20Accepted3/328ms6632 KiB
21Accepted3/329ms6964 KiB
22Accepted3/330ms7008 KiB