13022022-04-09 22:06:09ZsofiaKeresztelyPletykacpp14Time limit exceeded 82/100186ms26696 KiB
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair

int main() {
	int n, m, k, c=0;
	cin>>n>>m>>k;
	vector<vector<int> > g(n+1);
	vector<vector<bool> > volt(2, vector<bool>(n+1, false));
	vector<vector<int> > tav(2, vector<int>(n+1, 0));
	vector<int> napok(2*n, 0);
	vector<int> merges(k);
	queue<pair<int, int> > q; //sorszama, paritas
	for (int i=0; i<k; i++)
	{
		cin>>merges[i];
		q.push(mp(merges[i], 0));
		volt[0][merges[i]]=true;
	}
	int a, b;
	for (int i=0; i<m; i++)
	{
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for (int x : merges)
	{
		if (!g[x].size())
		{
			c++;
		}
	}
	pair<int, int> elso;
	while (!q.empty())
	{
		elso=q.front();
		q.pop();
		for (int x : g[elso.first])
		{
			if (!volt[1-elso.second][x])
			{
				volt[1-elso.second][x]=true;
				q.push(mp(x, 1-elso.second));
				tav[1-elso.second][x]=tav[elso.second][elso.first]+1;
				napok[tav[1-elso.second][x]]++;
			}
		}
	}
	napok[0]=k-c;
	int maxi=0;
	if (napok[1]>napok[maxi])
	{
		maxi=1;
	}
	for (int i=2; i<2*n; i++)
	{
		napok[i]+=napok[i-2];
		if (napok[i]>napok[maxi])
		{
			maxi=i;
		}
	}
	if (k>napok[maxi])
	{
		maxi=0;
	}
	napok[0]=k;
	cout<<napok[maxi]<<"\n"<<maxi+1<<"\n";
	for (int i=0; i<=maxi; i++)
	{
		cout<<napok[i]<<" ";
	}
}
SubtaskSumTestVerdictTimeMemory
base82/100
1Accepted0/02ms1796 KiB
2Accepted0/032ms6232 KiB
3Accepted2/21ms2184 KiB
4Accepted2/22ms2252 KiB
5Accepted2/23ms2472 KiB
6Accepted2/24ms2956 KiB
7Accepted4/44ms3000 KiB
8Accepted4/48ms3688 KiB
9Accepted4/49ms3784 KiB
10Accepted4/48ms3880 KiB
11Accepted4/430ms6968 KiB
12Accepted4/428ms7300 KiB
13Accepted4/452ms10772 KiB
14Accepted4/452ms11408 KiB
15Accepted6/678ms14992 KiB
16Accepted6/670ms15800 KiB
17Accepted6/686ms19616 KiB
18Accepted6/6109ms20740 KiB
19Accepted6/6115ms23096 KiB
20Accepted6/6112ms24352 KiB
21Accepted6/6115ms25516 KiB
22Time limit exceeded0/6126ms26696 KiB
23Time limit exceeded0/6170ms21996 KiB
24Time limit exceeded0/6186ms25032 KiB