39342023-03-05 22:04:02SleepyOverlordElágazás nélküli úton levő települések (50 pont)cpp17Accepted 50/5028ms6120 KiB
#include <vector>
#include <string> 
#include <set> 
#include <map> 
#include <unordered_set>
#include <unordered_map>
#include <queue> 
#include <bitset> 
#include <stack>
#include <list>

#include <numeric> 
#include <algorithm> 
#include <random>
#include <chrono>

#include <cstdio>
#include <fstream>
#include <iostream> 
#include <sstream> 
#include <iomanip>
#include <climits>

#include <cctype>
#include <cmath> 
#include <ctime>
#include <cassert>

using namespace std;

#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap

#define FORN(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define SZ size()
#define BG begin() 
#define EN end() 
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count

#define IN_FILE "a.in"
#define OUT_FILE "a.out"

template <typename T>
void PR(T var1)
{
	cout << var1 <<endl;
}
template <typename T, typename... Types>
void PR(T var1, Types... var2)
{
	cout << var1;
	PR(var2...);
}

int n, m;
VVI g;
SI sol;

int main()
{
	cin >> n >> m;
	g.RS(n + 1);
	FOR(i, 1, m)
	{
		int x, y;
		cin >> x >> y;
		g[x].PB(y);
		g[y].PB(x);
	}

	FOR(i, 1, n) 
		if (g[i].SZ == 1)
		{	
			int node = g[i][0];
			int prev = i;
			while (g[node].SZ <= 2)
			{
				sol.INS(node);
				int next = -1;
				if (g[node][0] != prev)	next = g[node][0];
				else if (g[node].SZ == 2) next = g[node][1];
				if (next == -1) break;
				prev = node;
				node = next;
			}
			sol.INS(node);
		}

	PR(sol.SZ);
	for (auto i : sol) cout << i << " ";
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1876 KiB
2Accepted0/028ms3988 KiB
3Accepted2/22ms2332 KiB
4Accepted2/22ms2672 KiB
5Accepted2/22ms2700 KiB
6Accepted2/22ms2764 KiB
7Accepted2/22ms2908 KiB
8Accepted2/24ms3324 KiB
9Accepted2/26ms3456 KiB
10Accepted2/28ms3812 KiB
11Accepted2/214ms4480 KiB
12Accepted2/216ms4456 KiB
13Accepted3/34ms3652 KiB
14Accepted3/34ms3980 KiB
15Accepted3/36ms4148 KiB
16Accepted3/37ms4384 KiB
17Accepted3/314ms4804 KiB
18Accepted3/314ms5224 KiB
19Accepted3/317ms5732 KiB
20Accepted3/328ms5940 KiB
21Accepted3/328ms6120 KiB
22Accepted3/328ms6084 KiB