163102025-04-28 10:32:23GervidPletykacpp17Wrong answer 63/100101ms8764 KiB
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits.h>
#include <algorithm>
#include <math.h>
#include <array>

using namespace std;

int main()
{
	iostream::sync_with_stdio(0);
	cin.tie(0);

	int n, m, k, i, a, b;
	cin >> n >> m >> k;

	vector<int> state(n, 0);
	queue<int> q;
	for (i = 0; i < k; i++)
	{
		cin >> a;
		q.push(--a);
		state[a] = 1;
	}
	q.push(-1);

	vector<vector<int>> g(n);
	for (i = 0; i < m; i++)
	{
		cin >> a >> b;
		g[--a].push_back(--b);
		g[b].push_back(a);
	}

	vector<int> days;
	vector<array<int, 2>> update;
	days.reserve(2 * n + 2), update.reserve(n);
	int odd = k, even = 0; //first day is odd, but zero indexed

	while (true)
	{
		int node = q.front();
		q.pop();
		if (node < 0)
		{
			while (!update.empty())
			{
				if ((state[update.back()[0]] & update.back()[1]) == 0)
				{
					if (update.back()[1] == 1) odd++;
					if (update.back()[1] == 2) even++;
					state[update.back()[0]] |= update.back()[1];
					q.push(update.back()[0]);
				}
				update.pop_back();
			}
			days.push_back((node == -1) ? odd : even);
			if (q.empty()) break;
			q.push((node == -1) ? -2 : -1);
			continue;
		}
		for (int neighbour : g[node])
		{
			if ((state[node] & 1) > 0 && (state[neighbour] & 2) == 0) update.push_back({ neighbour, 2 });
			if ((state[node] & 2) > 0 && (state[neighbour] & 1) == 0) update.push_back({ neighbour, 1 });
		}
	}

	int maxv = -1;
	for (i = days.size() - 1; i >= 0; i--)
	{
		if (days[i] >= maxv)
		{
			maxv = days[i];
			days.resize(i + 1);
		}
	}

	cout << days.back() << '\n' << days.size() << '\n';
	for (i = 0; i < days.size(); i++) cout << days[i] << ' ';
}
//5 4 4
//1 2 4 5
//1 2
//2 3
//3 4
//4 5

SubtaskSumTestVerdictTimeMemory
base63/100
1Accepted0/01ms500 KiB
2Wrong answer0/017ms2356 KiB
3Accepted2/21ms508 KiB
4Partially correct1/21ms316 KiB
5Wrong answer0/22ms316 KiB
6Wrong answer0/23ms564 KiB
7Accepted4/43ms728 KiB
8Wrong answer0/46ms1076 KiB
9Accepted4/44ms864 KiB
10Accepted4/44ms860 KiB
11Wrong answer0/417ms2208 KiB
12Accepted4/416ms2056 KiB
13Partially correct2/425ms3484 KiB
14Wrong answer0/427ms3596 KiB
15Wrong answer0/639ms4764 KiB
16Accepted6/641ms4852 KiB
17Wrong answer0/659ms6000 KiB
18Accepted6/652ms5932 KiB
19Accepted6/654ms6540 KiB
20Wrong answer0/663ms6376 KiB
21Accepted6/652ms6328 KiB
22Accepted6/667ms6708 KiB
23Accepted6/6101ms8756 KiB
24Accepted6/6101ms8764 KiB