Submission #592468

#TimeUsernameProblemLanguageResultExecution timeMemory
592468franfillToy Train (IOI17_train)C++17
100 / 100
889 ms1716 KiB
#include "train.h"
#include<queue>
#include<iostream>
using namespace std;

vector<int> who_wins(vector<int> a, vector<int> re, vector<int> u, vector<int> v) {
	int n = a.size(), m = u.size();
	vector < vector < int > > g(n);
	vector < vector < int > > r(n);
	for (int i = 0; i < m; i++)
	{
		g[u[i]].emplace_back(v[i]);
		r[v[i]].emplace_back(u[i]);
	}	

	vector < bool > used(n, 0);
	while(true)
	{
		vector < bool > good(n);
		queue < int > q;
		for (int i = 0; i < n; i++) if (!used[i])
		{
			if (re[i]) 
			{
				good[i] = true;
				q.emplace(i);
			}
		}
		vector < int > cnt(n, 0);
		for (int x = 0; x < n; x++)
		{
			for (auto y : g[x]) if (used[y])
			{
				cnt[x]++;
			}
		}

		while(!q.empty())
		{
			int x = q.front();
			q.pop();

			for (auto y : r[x]) if (!used[y] && !good[y])
			{
				cnt[y]++;
				if (a[y] || cnt[y] == g[y].size())
				{
					good[y] = true;
					q.emplace(y);
				}
			}
		}

		cnt.assign(n, 0);
		for (int x = 0; x < n; x++)
		{
			for (auto y : g[x]) if (used[y])
			{
				cnt[x]++;
			}
		}
		
		bool ok = true;
		for (int x = 0; x < n; x++) if (!used[x] && !good[x]) 
		{
			used[x] = true;
			q.push(x);
			ok = false;
		}
		if (ok) break;

		while(!q.empty())
		{
			int x = q.front();
			q.pop();

			for (auto y : r[x]) if (!used[y])
			{
				cnt[y]++;
				if (!a[y] || cnt[y] == g[y].size())
				{
					used[y] = true;
					q.emplace(y);
				}
			}
		}
	}
	vector < int > ans;
	for (auto b : used)
	{
		if (b) ans.emplace_back(0);
		else ans.emplace_back(1);
	}

	return ans;
}

Compilation message (stderr)

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:46:24: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     if (a[y] || cnt[y] == g[y].size())
train.cpp:80:25: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     if (!a[y] || cnt[y] == g[y].size())
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...