73752024-01-08 11:58:09szabelrElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 4/5028ms4508 KiB
#include <iostream>

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;
    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;
    for(int i=1; i<=q-1; i++){
        cout<<jok[i]<<" ";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base4/50
1Accepted0/03ms1904 KiB
2Wrong answer0/027ms2840 KiB
3Wrong answer0/23ms2324 KiB
4Wrong answer0/23ms2396 KiB
5Accepted2/23ms2624 KiB
6Wrong answer0/23ms2740 KiB
7Wrong answer0/23ms2828 KiB
8Wrong answer0/24ms2980 KiB
9Wrong answer0/26ms3332 KiB
10Wrong answer0/28ms3484 KiB
11Accepted2/214ms3644 KiB
12Wrong answer0/214ms3648 KiB
13Wrong answer0/34ms3652 KiB
14Wrong answer0/36ms3700 KiB
15Wrong answer0/38ms3720 KiB
16Wrong answer0/319ms3728 KiB
17Wrong answer0/321ms3796 KiB
18Wrong answer0/328ms4080 KiB
19Wrong answer0/328ms4188 KiB
20Wrong answer0/326ms4432 KiB
21Wrong answer0/327ms4508 KiB
22Wrong answer0/327ms4508 KiB