229042026-01-16 08:16:57bombinigusiniElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 31/5013ms1332 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    //ifstream cin ("f.txt");
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m, x, y, z;
    cin>>n>>m;
    vector<vector<int>> v1(n+1);
    bool volt[n+1]={};
    for(int i=1; i<=m; i++)
    {
        cin>>x>>y;
        v1[x].push_back(y);
        v1[y].push_back(x);
    }
    vector<int> vegfalu;
    queue<int> q;
    for(int i=1; i<=n; i++)
    {
        if(v1[i].size()==1)
        {
            vegfalu.push_back(i);
            volt[i]=true;
            //cout<<i<<" ";
        }
    }
    vector<int> megoldas;
    for(auto i: vegfalu)
    {
        q.push(i);
        while(!q.empty())
        {
            z=q.front();
            q.pop();
            for(auto j:v1[z])
            {
                if(volt[j]==false and v1[j].size()==2)
                {
                    megoldas.push_back(j);
                    volt[j]=true;
                    q.push(j);
                }
                if(volt[j]==false and v1[j].size()==1)
                {
                    megoldas.push_back(j);
                    megoldas.push_back(i);
                    volt[j]=true;
                }
                if(!volt[j]){
                    megoldas.push_back(j);
                    volt[j]=true;
                }
            }
        }
    }
    cout<<megoldas.size()<<endl;
    sort(megoldas.begin(), megoldas.end());
    for(int i=0; i<megoldas.size(); i++)
    {
        cout<<megoldas[i]<<" ";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base31/50
1Accepted0/01ms316 KiB
2Accepted0/013ms1332 KiB
3Wrong answer0/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Wrong answer0/21ms316 KiB
7Accepted2/21ms500 KiB
8Accepted2/22ms316 KiB
9Accepted2/23ms572 KiB
10Accepted2/24ms556 KiB
11Accepted2/27ms716 KiB
12Accepted2/27ms820 KiB
13Accepted3/32ms456 KiB
14Wrong answer0/32ms316 KiB
15Wrong answer0/33ms748 KiB
16Wrong answer0/33ms644 KiB
17Wrong answer0/36ms856 KiB
18Wrong answer0/36ms820 KiB
19Accepted3/38ms1076 KiB
20Accepted3/313ms1272 KiB
21Accepted3/313ms1140 KiB
22Accepted3/313ms1244 KiB