141082025-01-09 19:35:24BencuElágazás nélküli úton levő települések (50 pont)cpp17Runtime error 2/5032ms32000 KiB
#include <bits/stdc++.h>

using namespace std;
int n,m,a[10001][10001],b[10001],M[10001],s;
bool meg[10001];
void be() {
    ifstream f("be.in");
    cin>>n>>m;
    for (int i=1; i<=m; i++) {
        int x,y;
        cin>>x>>y;
        a[x][y]=1;
        a[y][x]=1;
        b[x]++;
        b[y]++;
    }
}
void bejar(int x) {
    int i=1;
    while (a[i][x]!=1 || meg[i]==1) i++;
    if(meg[i]==0) {
        M[s]=i;
        s++;
        meg[i]=1;
        if (b[i]==2) bejar(i);
    }
}

int main()
{
    be();
    //for (int i=1; i<=n; i++) cout<<i<<"-"<<b[i]<<endl;
    for (int i=1; i<=n; i++) {
        if(b[i]==1) {
            meg[i]=1;
            bejar(i);
        }
    }
    if (s!=0) {
        cout<<s<<endl;
        for (int i=0; i<s; i++) cout<<M[i]<<" ";
    }
    else cout<<0;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base2/50
1Accepted0/01ms512 KiB
2Runtime error0/032ms32000 KiB
3Runtime error0/212ms1076 KiB
4Runtime error0/212ms1076 KiB
5Accepted2/21ms316 KiB
6Runtime error0/212ms1076 KiB
7Wrong answer0/21ms508 KiB
8Wrong answer0/27ms6964 KiB
9Wrong answer0/217ms18752 KiB
10Runtime error0/228ms32000 KiB
11Runtime error0/228ms32000 KiB
12Runtime error0/232ms32000 KiB
13Runtime error0/316ms7112 KiB
14Runtime error0/327ms16972 KiB
15Runtime error0/332ms26420 KiB
16Runtime error0/332ms32000 KiB
17Runtime error0/326ms32000 KiB
18Runtime error0/330ms32000 KiB
19Runtime error0/327ms32000 KiB
20Runtime error0/326ms32000 KiB
21Runtime error0/332ms32000 KiB
22Runtime error0/325ms32000 KiB