57782023-09-27 07:46:59zsebiElágazás nélküli úton levő települések (50 pont)cpp11Hibás válasz 25/5029ms7288 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
{
    bool lat = false;
    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);
            while (!v.empty())
            {
                ll akt = v.front();
               
                v.pop_front();
                lat[akt] = 1;
                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);
                    }
                }

            }
      
    }
    sort(ans.begin(), ans.end());
    cout << ans.size() << "\n";
    for (auto& e : ans)cout << e<<" ";
    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
RészfeladatÖsszpontTesztVerdiktIdőMemória
base25/50
1Elfogadva0/03ms1812 KiB
2Elfogadva0/029ms4912 KiB
3Hibás válasz0/22ms2368 KiB
4Hibás válasz0/22ms2368 KiB
5Elfogadva2/22ms2468 KiB
6Elfogadva2/22ms2612 KiB
7Elfogadva2/22ms2696 KiB
8Elfogadva2/24ms3088 KiB
9Elfogadva2/26ms3576 KiB
10Elfogadva2/28ms3960 KiB
11Elfogadva2/216ms4768 KiB
12Elfogadva2/216ms4940 KiB
13Hibás válasz0/34ms3996 KiB
14Hibás válasz0/34ms4152 KiB
15Hibás válasz0/36ms4480 KiB
16Hibás válasz0/38ms4732 KiB
17Hibás válasz0/314ms5436 KiB
18Hibás válasz0/316ms6004 KiB
19Hibás válasz0/318ms6400 KiB
20Elfogadva3/329ms7260 KiB
21Elfogadva3/329ms7288 KiB
22Elfogadva3/329ms7288 KiB