73992024-01-08 14:05:50madvirElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 0/50300ms12928 KiB
#include <iostream>
#include <set>
#include <iterator>

using namespace std;

int main()
{
    int n, m, honnan, hova;
    cin >> n >> m;
    set<int> tel[n+1], zsak, elerheto;
    set<int>::iterator ptr, ptr2, ptr3;

    for(int i=1; i<=m; i++) {
        cin >> honnan;
        cin >> hova;
        tel[honnan].insert(hova);
        tel[hova].insert(honnan);
    }

    for(int i=1; i<=n; i++) {
        if(tel[i].size()==1) {
            zsak.insert(i);
        }
    }

    int tart=0, utolso;
    for(ptr=zsak.begin(); ptr!=zsak.end(); ptr++) {
        ptr2=tel[*ptr].begin();
        tart=*ptr2;
        elerheto.insert(tart);
        cout << "Innen kezd: " << tart << ", ";
        while(tel[tart].size()==2) {

            ptr2=tel[tart].begin();
            if(*ptr2==*ptr) {
                ptr2=tel[tart].end();
                tel[tart].erase(*ptr);
                ptr2=tel[tart].begin();
            }
            tart=*ptr2;
            elerheto.insert(tart);
        }
    }

    cout << "MASODIK RESZ" << endl;

    cout << elerheto.size() << endl;

    //ptr=elerheto.end();
    //utolso=*ptr;
    //elerheto.erase(utolso);

    for(ptr=elerheto.begin(); ptr!=elerheto.end(); ptr++) {
        cout << *ptr << " ";
    }
    //cout << utolso;


    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/03ms1812 KiB
2Wrong answer0/041ms10492 KiB
3Wrong answer0/23ms2308 KiB
4Wrong answer0/23ms2428 KiB
5Wrong answer0/23ms2788 KiB
6Wrong answer0/23ms2760 KiB
7Wrong answer0/23ms2956 KiB
8Wrong answer0/24ms4028 KiB
9Wrong answer0/28ms4928 KiB
10Wrong answer0/210ms5828 KiB
11Wrong answer0/220ms7896 KiB
12Wrong answer0/220ms8032 KiB
13Wrong answer0/34ms4536 KiB
14Time limit exceeded0/3266ms4024 KiB
15Wrong answer0/37ms5672 KiB
16Time limit exceeded0/3300ms4244 KiB
17Wrong answer0/317ms8032 KiB
18Wrong answer0/317ms8592 KiB
19Wrong answer0/323ms9376 KiB
20Wrong answer0/339ms12388 KiB
21Wrong answer0/339ms12908 KiB
22Wrong answer0/339ms12928 KiB