74002024-01-08 14:06:37madvirElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 36/50300ms11924 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);
        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 << 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
base36/50
1Accepted0/03ms1812 KiB
2Accepted0/039ms10440 KiB
3Wrong answer0/23ms2152 KiB
4Accepted2/23ms2256 KiB
5Accepted2/23ms2468 KiB
6Accepted2/23ms2648 KiB
7Accepted2/23ms2740 KiB
8Accepted2/24ms3576 KiB
9Accepted2/27ms4240 KiB
10Accepted2/210ms5044 KiB
11Accepted2/219ms7056 KiB
12Accepted2/219ms7100 KiB
13Accepted3/34ms3368 KiB
14Time limit exceeded0/3300ms2548 KiB
15Wrong answer0/37ms4244 KiB
16Time limit exceeded0/3300ms3052 KiB
17Accepted3/317ms6728 KiB
18Wrong answer0/317ms7032 KiB
19Accepted3/321ms7988 KiB
20Accepted3/337ms11400 KiB
21Accepted3/341ms11924 KiB
22Accepted3/339ms11924 KiB