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

using namespace std;
int hanyut[10001]{0};
int utkez[100001]{0};
int utveg[100001]{0};
int volt[100001]{0};
int jok[10001]{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[y];
                                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[y];
                                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[y];
                                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[y];
                                volt[z]=1;
                                db++;

                            }
                        }
                    }
                }

            }
        }
    }
    cout<<db<<endl;
    for(int i=1; i<=q-1; i++){
        cout<<jok[i]<<" ";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base4/50
1Accepted0/03ms1896 KiB
2Wrong answer0/027ms2816 KiB
3Wrong answer0/23ms2296 KiB
4Wrong answer0/23ms2380 KiB
5Accepted2/23ms2508 KiB
6Wrong answer0/23ms2716 KiB
7Wrong answer0/23ms2944 KiB
8Wrong answer0/24ms3044 KiB
9Wrong answer0/26ms3348 KiB
10Wrong answer0/28ms3592 KiB
11Accepted2/214ms4156 KiB
12Wrong answer0/214ms4240 KiB
13Wrong answer0/34ms3944 KiB
14Wrong answer0/36ms4192 KiB
15Wrong answer0/38ms4056 KiB
16Wrong answer0/319ms3964 KiB
17Wrong answer0/321ms4192 KiB
18Wrong answer0/328ms4216 KiB
19Wrong answer0/328ms4516 KiB
20Wrong answer0/325ms4704 KiB
21Wrong answer0/326ms4840 KiB
22Wrong answer0/328ms5228 KiB