Submission #735652

# Submission time Handle Problem Language Result Execution time Memory
735652 2023-05-04T12:34:43 Z Mister_HDS Bitaro’s Party (JOI18_bitaro) C++14
14 / 100
2000 ms 119272 KB
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define IOS                       \
	ios_base::sync_with_stdio(0); \
	cin.tie(0);                   \
	cout.tie(0);
using namespace std;
const ll MOD = 1e9 + 7;
const double EPS = 1e-7;
const int MAX = (int)1e5 + 10;
const double PI = acos(-1);

vector<int> adj[MAX];
vector<int> par[MAX];

vector<pair<int, int>> shits[MAX];
int frq[MAX];

bool removed[MAX];
int sqrt_n = 80;

void build(queue<int> q, vector<int> ind)
{
	while (!q.empty())
	{
		int curNode = q.front();
		q.pop();

		for (auto node : adj[curNode])
		{
			ind[node]--;
			if (ind[node] == 0)
				q.push(node);
		}

		vector<pair<int, int>> &res = shits[curNode];
		res.push_back({0, curNode});
		for (auto node : par[curNode])
		{
			for (auto x : shits[node])
			{
				frq[x.second] = max(frq[x.second], x.first + 1);
			}
		}
		for (auto node : par[curNode])
		{
			for (auto x : shits[node])
			{
				if (frq[x.second] > 0)
				{
					res.push_back({frq[x.second], x.second});
					frq[x.second] = 0;
				}
			}
		}
		sort(res.rbegin(), res.rend());
		while ((int)res.size() > sqrt_n)
		{
			res.pop_back();
		}
		// cout << curNode << endl;
		// for(auto x : res) cout << x.first << " " << x.second << endl ;
	}
}

int bfs(queue<int> q, vector<int> ind, int n, int nodeParty)
{
	vector<int> dis(n + 1, 0);
	while (!q.empty())
	{
		int curNode = q.front();
		q.pop();
		for (auto node : adj[curNode])
		{
			ind[node]--;
			if (ind[node] == 0)
				q.push(node);
			if (dis[curNode] == 0 && removed[curNode] == true)
				continue;
			dis[node] = max(dis[node], dis[curNode] + 1);
		}
	}
	return dis[nodeParty];
}

void solve()
{
	int n, m, q;
	cin >> n >> m >> q;
	vector<int> ind(n + 1, 0);
	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		par[v].push_back(u);
		ind[v]++;
	}
	queue<int> roots;
	for (int i = 1; i <= n; i++)
	{
		if (ind[i] == 0)
			roots.push(i);
	}

	build(roots, ind);

	while (q--)
	{
		int nodeParty, totalRemoved;
		vector<int> rmv;
		cin >> nodeParty >> totalRemoved;
		for (int i = 1; i <= totalRemoved; i++)
		{
			int node;
			cin >> node;
			rmv.push_back(node);
		}
		for (auto node : rmv)
			removed[node] = true;

		int sz = (int)rmv.size();
		int ans = -1;
		if (sz > sqrt_n)
		{ // FIRST TYPE OF QUESRIES
			ans = bfs(roots, ind, n, nodeParty);
		}
		else
		{
			for (auto node : shits[nodeParty])
			{
				if (removed[node.second] == false)
				{
					ans = max(ans, node.first);
				}
			}
		}
		if (ans == 0 && removed[nodeParty] == true)
			ans = -1;
		cout << ans << endl;
		for (auto node : rmv)
			removed[node] = false;
	}
}
int main()
{
	IOS;
	solve();

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 7 ms 7764 KB Output is correct
6 Correct 7 ms 7764 KB Output is correct
7 Correct 6 ms 7764 KB Output is correct
8 Correct 8 ms 8404 KB Output is correct
9 Correct 8 ms 8404 KB Output is correct
10 Correct 11 ms 8384 KB Output is correct
11 Correct 9 ms 8404 KB Output is correct
12 Correct 9 ms 8148 KB Output is correct
13 Correct 9 ms 8276 KB Output is correct
14 Correct 8 ms 8020 KB Output is correct
15 Correct 7 ms 7892 KB Output is correct
16 Correct 8 ms 7940 KB Output is correct
17 Correct 8 ms 8148 KB Output is correct
18 Correct 8 ms 7892 KB Output is correct
19 Correct 8 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 7 ms 7764 KB Output is correct
6 Correct 7 ms 7764 KB Output is correct
7 Correct 6 ms 7764 KB Output is correct
8 Correct 8 ms 8404 KB Output is correct
9 Correct 8 ms 8404 KB Output is correct
10 Correct 11 ms 8384 KB Output is correct
11 Correct 9 ms 8404 KB Output is correct
12 Correct 9 ms 8148 KB Output is correct
13 Correct 9 ms 8276 KB Output is correct
14 Correct 8 ms 8020 KB Output is correct
15 Correct 7 ms 7892 KB Output is correct
16 Correct 8 ms 7940 KB Output is correct
17 Correct 8 ms 8148 KB Output is correct
18 Correct 8 ms 7892 KB Output is correct
19 Correct 8 ms 8148 KB Output is correct
20 Correct 95 ms 10724 KB Output is correct
21 Correct 94 ms 10756 KB Output is correct
22 Correct 93 ms 10756 KB Output is correct
23 Correct 97 ms 10660 KB Output is correct
24 Correct 660 ms 97472 KB Output is correct
25 Correct 654 ms 95556 KB Output is correct
26 Correct 648 ms 95396 KB Output is correct
27 Correct 532 ms 117444 KB Output is correct
28 Correct 564 ms 117448 KB Output is correct
29 Correct 618 ms 117400 KB Output is correct
30 Correct 603 ms 116812 KB Output is correct
31 Correct 742 ms 119272 KB Output is correct
32 Correct 606 ms 116616 KB Output is correct
33 Correct 499 ms 80332 KB Output is correct
34 Correct 706 ms 97824 KB Output is correct
35 Correct 527 ms 79928 KB Output is correct
36 Correct 582 ms 98512 KB Output is correct
37 Correct 716 ms 101264 KB Output is correct
38 Correct 525 ms 98488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 7 ms 7764 KB Output is correct
6 Correct 7 ms 7764 KB Output is correct
7 Correct 6 ms 7764 KB Output is correct
8 Correct 8 ms 8404 KB Output is correct
9 Correct 8 ms 8404 KB Output is correct
10 Correct 11 ms 8384 KB Output is correct
11 Correct 9 ms 8404 KB Output is correct
12 Correct 9 ms 8148 KB Output is correct
13 Correct 9 ms 8276 KB Output is correct
14 Correct 8 ms 8020 KB Output is correct
15 Correct 7 ms 7892 KB Output is correct
16 Correct 8 ms 7940 KB Output is correct
17 Correct 8 ms 8148 KB Output is correct
18 Correct 8 ms 7892 KB Output is correct
19 Correct 8 ms 8148 KB Output is correct
20 Correct 95 ms 10724 KB Output is correct
21 Correct 94 ms 10756 KB Output is correct
22 Correct 93 ms 10756 KB Output is correct
23 Correct 97 ms 10660 KB Output is correct
24 Correct 660 ms 97472 KB Output is correct
25 Correct 654 ms 95556 KB Output is correct
26 Correct 648 ms 95396 KB Output is correct
27 Correct 532 ms 117444 KB Output is correct
28 Correct 564 ms 117448 KB Output is correct
29 Correct 618 ms 117400 KB Output is correct
30 Correct 603 ms 116812 KB Output is correct
31 Correct 742 ms 119272 KB Output is correct
32 Correct 606 ms 116616 KB Output is correct
33 Correct 499 ms 80332 KB Output is correct
34 Correct 706 ms 97824 KB Output is correct
35 Correct 527 ms 79928 KB Output is correct
36 Correct 582 ms 98512 KB Output is correct
37 Correct 716 ms 101264 KB Output is correct
38 Correct 525 ms 98488 KB Output is correct
39 Correct 746 ms 96808 KB Output is correct
40 Correct 659 ms 94192 KB Output is correct
41 Execution timed out 2086 ms 95992 KB Time limit exceeded
42 Halted 0 ms 0 KB -