97962024-03-06 23:37:11SleepyOverlordFertőzési sorozat (50 pont)cpp17Accepted 50/5014ms4928 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 MX(x, y) x = max(x, y);
#define MN(x, y) x = min(x, y);

#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

template <class T> ostream& operator <<(ostream & os, const vector<T> &vec)
{
	for (int i = 0; i < vec.size() - 1; ++i) os << vec[i] << ' ';
	return os << vec[vec.size() - 1];
}

template <class T1, class T2> ostream& operator <<(ostream & os, const pair<T1, T2> &p)
{
	return os << p.X << " " << p.Y;
}

template <typename T>
void pr(T var1)
{
	cout << var1 << '\n';
}
template <typename T, typename... Types>
void pr(T var1, Types... var2)
{
	cout << var1;
	pr(var2...);
}

void in(int &n, VI &a) //array of ints
{
	cin >> n;
	a.CL, a.RS(n + 1);
	FOR(i, 1, n) cin >> a[i];
}

void in(int &n, VS &a) //array of strings
{
	cin >> n;
	a.CL, a.RS(n + 1);
	FOR(i, 1, n) cin >> a[i];
}

void in(int &n, VPII &a) //array of pairs
{
	cin >> n;
	a.CL, a.RS(n + 1);
	FOR(i, 1, n) cin >> a[i].X >> a[i].Y;
}

void in(int &n, int &m, VVI &g) //unweighted graph
{
	cin >> n >> m;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n)
	{
		int x, y;
		cin >> x >> y;
		g[x].PB(y);
		g[y].PB(x);
	}
}

void in(int &n, VVI &g) //unweighted tree
{
	cin >> n;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n - 1)
	{
		int x, y;
		cin >> x >> y;
		g[x].PB(y);
		g[y].PB(x);
	}
}

void in(int &n, int &m, vector <VPII> &g) //weighted graph
{
	cin >> n >> m;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n)
	{
		int x, y, z;
		cin >> x >> y >> z;
		g[x].PB({y, z});
		g[y].PB({x, z});
	}
}

void in(int &n, vector <VPII> &g) //weighted tree
{
	cin >> n;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n - 1)
	{
		int x, y, z;
		cin >> x >> y >> z;
		g[x].PB({y, z});
		g[y].PB({x, z});
	}
}

int n, m, k;
VI a, sol, b, d;
VVI g;
VB was;

int main()
{
	#ifdef AT_HOME
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
	#endif

	cin >> n >> m >> k;
	a.RS(k + 1);
	FOR(i, 1, k) cin >> a[i];
	g.RS(n + 1);
	FOR(i, 1, m)
	{
		int x, y;
		cin >> x >> y;
		g[x].PB(y);
		g[y].PB(x);
	}
	b.RS(n + 1);
	d.RS(n + 1);
	was.RS(n + 1);
	FOR(i, 1, n)
	{
		fill(ALL(was), false);
		int l, r;
		l = r = 1;
		b[l] = i;
		was[i] = true;
		d[i] = 0;
		while (l < n)
		{
			int node = b[l++];
			for (int next : g[node])
				if (!was[next])
				{
					b[++r] = next;
					d[next] = d[node] + 1;
					was[next] = true;
				}
		}
		bool ok = d[a[k]] >= d[a[1]];
		FOR(i, 1, k - 1)
			if (d[a[i]] > d[a[i + 1]])
			{
				ok = false;
				break;
			}
		if (ok and d[a[k]] > d[a[1]] + 1)
		{
			fill(ALL(was), false);
			FOR(i, 1, k) was[a[i]] = true;
			FOR(i, 1, n)
				if (!was[i] and d[i] > d[a[1]] and d[i] < d[a[k]])
				{
					ok = false;
					break;
				}
		}
		if (ok) sol.PB(i);
	}
	pr(sol.SZ);
	for(int x : sol) cout << x << " ";

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1812 KiB
2Accepted0/03ms2008 KiB
3Accepted0/06ms2236 KiB
4Accepted2/23ms2444 KiB
5Accepted2/23ms2656 KiB
6Accepted2/24ms2808 KiB
7Accepted2/24ms2852 KiB
8Accepted2/26ms3048 KiB
9Accepted2/26ms3132 KiB
10Accepted2/214ms3236 KiB
11Accepted1/13ms3384 KiB
12Accepted2/26ms3184 KiB
13Accepted2/27ms3444 KiB
14Accepted2/24ms3512 KiB
15Accepted2/26ms3772 KiB
16Accepted2/27ms3856 KiB
17Accepted2/24ms3940 KiB
18Accepted1/16ms4028 KiB
19Accepted1/17ms4160 KiB
20Accepted1/14ms4384 KiB
21Accepted1/114ms4348 KiB
22Accepted1/114ms4352 KiB
23Accepted1/112ms4320 KiB
24Accepted1/112ms4444 KiB
25Accepted1/112ms4428 KiB
26Accepted1/113ms4564 KiB
27Accepted1/114ms4520 KiB
28Accepted1/113ms4600 KiB
29Accepted1/113ms4516 KiB
30Accepted1/112ms4664 KiB
31Accepted1/112ms4644 KiB
32Accepted1/113ms4928 KiB
33Accepted1/114ms4900 KiB
34Accepted1/114ms4672 KiB
35Accepted1/114ms4652 KiB
36Accepted1/114ms4656 KiB
37Accepted1/114ms4788 KiB
38Accepted1/114ms4844 KiB
39Accepted1/113ms4656 KiB
40Accepted1/114ms4568 KiB