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

void bejar(int x, set <int> &megold, vector <int> fokszam, int n, vector <int> a){
    int i;
    vector <bool> volt;
    volt.resize(n);
    volt[x] = 1;
    do{
        i=0;
        while(a[x*n+i] == 0 || volt[i] == 1 ){
            i ++;
        }
      if(fokszam[i] != 1)
      {
        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;
    }
    vector <int> fokszam;
    fokszam.resize(n);
    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;
    if(halmaz.size() != 0){
         for(auto i : halmaz)
        cout << i << " ";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base13/50
1Accepted0/01ms320 KiB
2Runtime error0/034ms32000 KiB
3Wrong answer0/21ms320 KiB
4Accepted2/21ms320 KiB
5Accepted2/21ms320 KiB
6Wrong answer0/21ms320 KiB
7Accepted2/21ms328 KiB
8Accepted2/225ms8180 KiB
9Accepted2/2151ms31564 KiB
10Runtime error0/232ms32000 KiB
11Runtime error0/232ms32000 KiB
12Runtime error0/228ms32000 KiB
13Accepted3/370ms8232 KiB
14Time limit exceeded0/3301ms31544 KiB
15Runtime error0/335ms32000 KiB
16Runtime error0/328ms32000 KiB
17Runtime error0/328ms32000 KiB
18Runtime error0/328ms32000 KiB
19Runtime error0/328ms32000 KiB
20Runtime error0/328ms32000 KiB
21Runtime error0/341ms32000 KiB
22Runtime error0/328ms32000 KiB