82262024-01-12 22:01:44bovizdbElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 0/5052ms64740 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);
    }
    for (ll i = 0; i < n; i++)
    {
        for (ll j : g[i]) cout << j << " ";
        cout << endl;
    }
    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
base0/50
1Wrong answer0/03ms1828 KiB
2Wrong answer0/023ms4908 KiB
3Runtime error0/252ms64740 KiB
4Wrong answer0/23ms2212 KiB
5Wrong answer0/23ms2356 KiB
6Wrong answer0/23ms2584 KiB
7Wrong answer0/23ms2652 KiB
8Wrong answer0/24ms3048 KiB
9Wrong answer0/26ms3584 KiB
10Wrong answer0/27ms3844 KiB
11Wrong answer0/212ms4552 KiB
12Wrong answer0/212ms4760 KiB
13Wrong answer0/34ms3516 KiB
14Wrong answer0/34ms3616 KiB
15Wrong answer0/36ms4072 KiB
16Wrong answer0/36ms4220 KiB
17Wrong answer0/310ms4888 KiB
18Wrong answer0/312ms5148 KiB
19Wrong answer0/314ms5788 KiB
20Wrong answer0/321ms6684 KiB
21Wrong answer0/321ms6748 KiB
22Wrong answer0/321ms6872 KiB