74042024-01-08 14:44:27szabelrElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 21/5028ms5084 KiB
#include <iostream>
#include <algorithm>
using namespace std;
int hanyut[100001]{0};
int utkez[100001]{0};
int utveg[100001]{0};
int volt[100001]{0};
int jok[100001]{0};
int main()
{
    int n,m,x,y,most,elozo,db=0,q=1,regi=0;
    cin>>n>>m;
    for(int i=1; i<=m; i++)
    {
        cin>>x>>y;
        utkez[i]=x;
        utveg[i]=y;
        hanyut[x]++;
        hanyut[y]++;
    }
    for(int i=1; i<=n; i++)
    {
        if(hanyut[i]==1)
        {
            for(int y=1; y<=m; y++)
            {
                if(utkez[y]==i)
                {
                    jok[q]=utveg[y];
                    q++;
                    most=utveg[y];
                    elozo=utkez[y];
                    db++;
                    while(hanyut[most]==2)
                    {
                        for(int z=1; z<=m; z++)
                        {

                            if(utkez[z]==most and utveg[z]!= elozo and volt[z]==0 and hanyut[most]==2)
                            {
                                jok[q]=utveg[z];
                                q++;
                                most=utveg[z];
                                elozo=utkez[z];
                                volt[z]=1;
                                db++;


                            }
                            if(utveg[z]==most and utkez[z]!= elozo and volt[z]==0 and hanyut[most]==2)
                            {
                                jok[q]=utkez[z];
                                q++;
                                most=utkez[z];
                                elozo=utveg[z];
                                volt[z]=1;
                                db++;

                            }
                        }
                    }
                }

                if(utveg[y]==i)
                {
                    jok[q]=utkez[y];
                    q++;
                    most=utveg[y];
                    db++;
                    while(hanyut[most]==2)
                    {
                        for(int z=1; z<=m; z++)
                        {

                            if(utkez[z]==most and utveg[z]!= elozo and volt[z]==0 and hanyut[most]==2)
                            {
                                jok[q]=utveg[z];
                                q++;
                                most=utveg[z];
                                elozo=utkez[z];
                                volt[z]=1;
                                db++;


                            }
                            if(utveg[z]==most and utkez[z]!= elozo and volt[z]==0 and hanyut[most]==2)
                            {
                                jok[q]=utkez[z];
                                q++;
                                most=utkez[z];
                                elozo=utveg[z];
                                volt[z]=1;
                                db++;

                            }
                        }
                    }
                }

            }
        }
    }
    cout<<db<<endl;
    sort(jok+1, jok+q);
    for(int i=1; i<=q-1; i++){
        if(jok[i]!=regi)
            cout<<jok[i]<<" ";
        regi=jok[i];

    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base21/50
1Accepted0/03ms1904 KiB
2Accepted0/026ms2880 KiB
3Wrong answer0/23ms2432 KiB
4Wrong answer0/23ms2296 KiB
5Accepted2/23ms2528 KiB
6Accepted2/23ms2596 KiB
7Wrong answer0/23ms2712 KiB
8Accepted2/24ms2964 KiB
9Wrong answer0/26ms2928 KiB
10Accepted2/28ms3096 KiB
11Accepted2/213ms3492 KiB
12Accepted2/214ms3568 KiB
13Wrong answer0/34ms3444 KiB
14Wrong answer0/36ms3324 KiB
15Wrong answer0/38ms3496 KiB
16Wrong answer0/319ms3804 KiB
17Wrong answer0/321ms4288 KiB
18Wrong answer0/328ms4332 KiB
19Wrong answer0/328ms4528 KiB
20Accepted3/325ms4728 KiB
21Accepted3/326ms5004 KiB
22Accepted3/327ms5084 KiB