74062024-01-08 14:53:20szabelrElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 23/5028ms4768 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]!=jok[i-1]){
            //cout<<jok[i]<<" ";
            //regi=jok[i];
        }else
            db--;
    }
    cout<<db<<endl;
    for(int i=1; i<=q-1; i++){
        if(jok[i]!=jok[i-1]){
            cout<<jok[i]<<" ";
            //regi=jok[i];
        }
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base23/50
1Accepted0/03ms1904 KiB
2Accepted0/026ms2824 KiB
3Wrong answer0/23ms2580 KiB
4Accepted2/23ms2536 KiB
5Accepted2/23ms2672 KiB
6Accepted2/23ms2648 KiB
7Wrong answer0/23ms2652 KiB
8Accepted2/24ms2944 KiB
9Wrong answer0/26ms3188 KiB
10Accepted2/28ms3152 KiB
11Accepted2/213ms3508 KiB
12Accepted2/214ms3380 KiB
13Wrong answer0/34ms3364 KiB
14Wrong answer0/36ms3704 KiB
15Wrong answer0/38ms3652 KiB
16Wrong answer0/319ms3812 KiB
17Wrong answer0/321ms4016 KiB
18Wrong answer0/328ms4016 KiB
19Wrong answer0/328ms4300 KiB
20Accepted3/325ms4500 KiB
21Accepted3/326ms4640 KiB
22Accepted3/327ms4768 KiB