73802024-01-08 12:33:57szabelrElágazás nélküli úton levő települések (50 pont)cpp17Time limit exceeded 2/50300ms3836 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;
    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++){
        cout<<jok[i]<<" ";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base2/50
1Accepted0/03ms2072 KiB
2Time limit exceeded0/0272ms1708 KiB
3Time limit exceeded0/2257ms2260 KiB
4Time limit exceeded0/2257ms2384 KiB
5Accepted2/23ms2636 KiB
6Time limit exceeded0/2300ms2832 KiB
7Time limit exceeded0/2254ms2888 KiB
8Time limit exceeded0/2254ms3040 KiB
9Time limit exceeded0/2270ms3212 KiB
10Time limit exceeded0/2257ms2572 KiB
11Time limit exceeded0/2246ms3020 KiB
12Time limit exceeded0/2277ms3256 KiB
13Time limit exceeded0/3273ms2988 KiB
14Time limit exceeded0/3264ms3836 KiB
15Time limit exceeded0/3241ms2960 KiB
16Time limit exceeded0/3257ms3784 KiB
17Time limit exceeded0/3254ms3340 KiB
18Time limit exceeded0/3273ms3508 KiB
19Time limit exceeded0/3273ms3392 KiB
20Time limit exceeded0/3229ms3584 KiB
21Time limit exceeded0/3246ms3652 KiB
22Time limit exceeded0/3261ms3584 KiB