126872024-12-28 12:42:58GundischBalazsElágazás nélküli úton levő települések (50 pont)cpp17Runtime error 2/5043ms32000 KiB
#include <iostream>
#include <set>
#include <vector>
using namespace std;

void bejar(int x, set <int> &megold, int fokszam[], int n, vector <int> a){
    int i;
    bool volt[10001] = {0};
    volt[x] = 1;
    do{
        while(a[x*(n)+i] == 0 or volt[i] == 1 ){
            i ++;
        }
            megold.insert(i+1);
            volt[i] = 1;
        x = i;
    }while(fokszam[x] <= 2);
}

int main()
{
    vector <int> a;
    int  n, m;
    cin >> n >> m;
    a.resize((n)*(n));
    int x, y;
    for(int i = 0; i < m; i ++){
        cin >> x >> y;
        x--;
        y--;
        a[x*(n)+y] = 1;
        a[y*(n)+x] = 1;
    }
    int fokszam[10001] = {0};
    for(int i = 0 ; i < n; i ++){
        for(int j =  0; j < n; j ++){
            fokszam[i] += a[i*(n)+j];
        }
    }
    set <int> halmaz;
    for(int i = 0; i < n; i ++){
        if(fokszam[i] == 1){
            bejar(i, halmaz, fokszam,n,a);
        }
    }
    cout << halmaz.size() << endl;
    for(auto i : halmaz)
        cout << i << " ";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base2/50
1Runtime error0/01ms320 KiB
2Runtime error0/027ms32000 KiB
3Runtime error0/21ms320 KiB
4Runtime error0/21ms320 KiB
5Accepted2/21ms320 KiB
6Runtime error0/21ms320 KiB
7Runtime error0/21ms508 KiB
8Runtime error0/29ms8172 KiB
9Runtime error0/241ms31800 KiB
10Runtime error0/232ms32000 KiB
11Runtime error0/232ms32000 KiB
12Runtime error0/234ms32000 KiB
13Runtime error0/38ms8280 KiB
14Runtime error0/343ms31800 KiB
15Runtime error0/332ms32000 KiB
16Runtime error0/332ms32000 KiB
17Runtime error0/332ms32000 KiB
18Runtime error0/332ms32000 KiB
19Runtime error0/327ms32000 KiB
20Runtime error0/332ms32000 KiB
21Runtime error0/332ms32000 KiB
22Runtime error0/332ms32000 KiB