82272024-01-12 22:02:57bovizdbElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 4/5052ms64624 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define endl "\n"
#define pll pair<ll, ll>
#define fs first
#define sc second
#define vll vector<ll>
#define v2d vector<vector<ll>>
#define vpll vector<pll>
#define qll queue<ll>
#define stll stack<ll>
#define sll set<ll>
#define mll map<ll, ll>

ll n, m;
v2d g;

void solve()
{
    cin >> n >> m;
    g.resize(n);
    for (ll i = 0; i < m; i++)
    {
        ll in1, in2;
        cin >> in1 >> in2;
        g[in1-1].push_back(in2-1);
        g[in2-1].push_back(in1-1);
    }
    vll v;
    for (ll i = 0; i < n; i++)
    {
        if (g[i].size() == 1)
        {
            v.push_back(i);
        }
    }
    vll out;
    for (ll i : v)
    {
        ll p = i, last = -1;
        while(true)
        {
            if (g[p].size() > 2 || g[p].size() == 0) break;
            if (g[p][0] == last)
            {
                out.push_back(g[p][1]);
                last = p;
                p = g[p][1];
            }
            else
            {
                out.push_back(g[p][0]);
                last = p;
                p = g[p][0];
            }
        }
    }
    cout << out.size() << endl;
    for (ll i : out) cout << i+1 << " ";
}
 
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base4/50
1Accepted0/03ms2012 KiB
2Wrong answer0/014ms4872 KiB
3Runtime error0/252ms64624 KiB
4Wrong answer0/23ms2460 KiB
5Accepted2/23ms2688 KiB
6Wrong answer0/23ms2872 KiB
7Wrong answer0/23ms3104 KiB
8Wrong answer0/24ms3564 KiB
9Wrong answer0/24ms3896 KiB
10Wrong answer0/26ms4164 KiB
11Accepted2/28ms4520 KiB
12Wrong answer0/28ms4664 KiB
13Wrong answer0/33ms3408 KiB
14Wrong answer0/34ms3876 KiB
15Wrong answer0/34ms4024 KiB
16Wrong answer0/34ms4380 KiB
17Wrong answer0/38ms4940 KiB
18Wrong answer0/38ms5124 KiB
19Wrong answer0/39ms5760 KiB
20Wrong answer0/314ms6416 KiB
21Wrong answer0/314ms6912 KiB
22Wrong answer0/314ms6992 KiB