141692025-01-10 08:05:38BencuElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 4/5028ms1368 KiB
#include <bits/stdc++.h>

using namespace std;
int n,m,fok[10000],M[10000],s;
bool meg[10000];
vector<vector<int>>a(10000);

void be() {
    ifstream f("be.in");
    cin>>n>>m;
    for (int i=1; i<=m; i++) {
        int x,y;
        cin>>x>>y;
        a[x].push_back(y);
        a[y].push_back(x);
        fok[x]++;
        fok[y]++;
    }
}
void bejar(int x) {
    M[s]=x;
    s++;
    if(fok[x]==2) {
        int i=0;
        while(meg[a[x][i]]==1) i++;
        bejar(a[x][i]);
    }
}

int main()
{
    be();
    //for (int i=1; i<=n; i++) cout<<i<<"-"<<b[i]<<endl;
    for (int i=1; i<=n; i++) {
        if(fok[i]==1) {
            meg[i]=1;
            bejar(a[i][0]);
        }
    }
    if (s!=0) {
        cout<<s<<endl;
        for (int i=0; i<s; i++) cout<<M[i]<<" ";
    }
    else cout<<0;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base4/50
1Accepted0/01ms748 KiB
2Wrong answer0/028ms1368 KiB
3Wrong answer0/21ms564 KiB
4Wrong answer0/21ms564 KiB
5Accepted2/21ms564 KiB
6Wrong answer0/21ms564 KiB
7Wrong answer0/21ms564 KiB
8Wrong answer0/23ms564 KiB
9Wrong answer0/24ms768 KiB
10Wrong answer0/28ms772 KiB
11Accepted2/214ms988 KiB
12Wrong answer0/214ms820 KiB
13Wrong answer0/34ms564 KiB
14Wrong answer0/34ms568 KiB
15Wrong answer0/37ms736 KiB
16Wrong answer0/36ms868 KiB
17Wrong answer0/314ms936 KiB
18Wrong answer0/313ms820 KiB
19Wrong answer0/317ms1076 KiB
20Wrong answer0/328ms1164 KiB
21Wrong answer0/328ms1228 KiB
22Wrong answer0/328ms1340 KiB