255952026-02-20 21:42:55szentedElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 2/501ms508 KiB
#include <iostream>
#include <fstream>

using namespace std;

int a[101][101]={0};
int n; //csucs
int m; //el

void be(){
    ifstream f("be.in");
    f >> n >> m;
    int b,c;
    for(int i=1; i<=m; i++){
        f >> b >> c;
        a[b][c]=1;
        a[c][b]=1;
    }
}

int szomszedok(int csucs){
    int db=0;
    for(int i=1; i<=n; i++){
        if(a[csucs][i]==1) db++;
    }
    return db;
}

void ki(){
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
}

int main()
{
    be();
    /*ki();
    cout << "szomszedok: " << endl;
    for(int i=1; i<=n; i++){
        cout << i << " . csucs: " << szomszedok(i) << " db" << endl;
    }*/
    
    int db=0;
    int megoldas[101];
    bool megnezve[101];
    for(int i=1; i<=n; i++){
        megnezve[i]=false;
    }
    
    for(int i=1; i<=n; i++){
        if(szomszedok(i)==1 && megnezve[i]==false){
            megnezve[i]=true;
            int elozo=i;
            int most=0;
            int j=1;
            while(j<=n && a[i][j]!=1) j++;
            if(j<=n) most=j;
            while(szomszedok(most)==2){
                megoldas[db]=most;
                db++;
                megnezve[most]=true;
                bool megvan=false;
                int j=1;
                while(j<=n && megvan==false){
                    if(a[most][j]==1 && j!=elozo){
                        elozo=most;
                        most=j;
                        megvan=true;
                    }
                    j++;
                }
                
            }
            megoldas[db]=most;
            db++;
            megnezve[most]=true;
        }
    }
    cout << db << endl;
    for(int i=0; i<db; i++){
        if(i>0) cout << " ";
        cout << megoldas[i];
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base2/50
1Wrong answer0/01ms508 KiB
2Wrong answer0/01ms316 KiB
3Wrong answer0/21ms500 KiB
4Wrong answer0/21ms316 KiB
5Accepted2/21ms316 KiB
6Wrong answer0/21ms316 KiB
7Wrong answer0/21ms316 KiB
8Wrong answer0/21ms316 KiB
9Wrong answer0/21ms316 KiB
10Wrong answer0/21ms316 KiB
11Wrong answer0/21ms316 KiB
12Wrong answer0/21ms316 KiB
13Wrong answer0/31ms316 KiB
14Wrong answer0/31ms316 KiB
15Wrong answer0/31ms508 KiB
16Wrong answer0/31ms316 KiB
17Wrong answer0/31ms316 KiB
18Wrong answer0/31ms500 KiB
19Wrong answer0/31ms316 KiB
20Wrong answer0/31ms316 KiB
21Wrong answer0/31ms316 KiB
22Wrong answer0/31ms316 KiB