74052024-01-08 14:47:45szabelrElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 19/5028ms4788 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];
        }else
            db--;
    }
    cout<<db<<endl;
    for(int i=1; i<=q-1; i++){
        if(jok[i]!=regi){
            cout<<jok[i]<<" ";
            regi=jok[i];
        }
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base19/50
1Accepted0/03ms1904 KiB
2Accepted0/028ms2824 KiB
3Wrong answer0/23ms2456 KiB
4Wrong answer0/23ms2520 KiB
5Accepted2/23ms2728 KiB
6Accepted2/23ms2960 KiB
7Wrong answer0/22ms3044 KiB
8Accepted2/24ms3400 KiB
9Wrong answer0/26ms3536 KiB
10Accepted2/28ms3628 KiB
11Wrong answer0/214ms3976 KiB
12Accepted2/214ms3928 KiB
13Wrong answer0/34ms3780 KiB
14Wrong answer0/36ms3940 KiB
15Wrong answer0/38ms4156 KiB
16Wrong answer0/319ms4120 KiB
17Wrong answer0/321ms4352 KiB
18Wrong answer0/328ms4412 KiB
19Wrong answer0/328ms4548 KiB
20Accepted3/326ms4632 KiB
21Accepted3/327ms4788 KiB
22Accepted3/328ms4776 KiB