답안 #1077979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077979 2024-08-27T11:22:45 Z Elias 장난감 기차 (IOI17_train) C++17
0 / 100
2000 ms 2396 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

#ifdef _DEBUG
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v);
#else
#include "train.h"
#endif

vector<set<int>> adj;

vector<int> visited;
vector<int> reachable_chargers;

vector<int> chargers;

void dfs_find_chargers(int i)
{
	if (visited[i])
		return;
	visited[i] = true;
	if (chargers[i])
		reachable_chargers.push_back(i);

	for (int c : adj[i])
	{
		dfs_find_chargers(c);
	}
}

bool dfs_find_loop(int i, int start)
{
	if (visited[i])
		return 0;
	visited[i] = true;
	bool any = false;
	for (int c : adj[i])
	{
		if (c == start)
			return true;
		any |= dfs_find_loop(c, start);
	}
	return any;
}

std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v)
{
	int n = a.size();
	chargers = r;
	adj.resize(n);
	for (int i = 0; i < u.size(); i++)
	{
		adj[u[i]].insert(v[i]);
	}

	vector<int> output;

	for (int q = 0; q < n; q++)
	{
		visited = vector<int>(n);
		reachable_chargers.clear();

		dfs_find_chargers(q);

		bool any = false;

		for (int i : reachable_chargers)
		{
			visited = vector<int>(n);

			any |= dfs_find_loop(i, i);
		}

		output.push_back(any);
	}
	return output;
}

#ifdef _DEBUG

using namespace std;

int main()
{
	int n, m;
	assert(2 == scanf("%d %d", &n, &m));

	vector<int> a(n), r(n), u(m), v(m);

	for (int i = 0; i < n; i++)
		assert(1 == scanf("%d", &a[i]));

	for (int i = 0; i < n; i++)
		assert(1 == scanf("%d", &r[i]));

	for (int i = 0; i < m; i++)
		assert(2 == scanf("%d %d", &u[i], &v[i]));

	vector<int> res = who_wins(a, r, u, v);

	for (int i = 0; i < (int)res.size(); i++)
		printf(i ? " %d" : "%d", res[i]);
	printf("\n");

	return 0;
}

#endif

Compilation message

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:54:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |  for (int i = 0; i < u.size(); i++)
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2052 ms 1372 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 8th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2072 ms 2396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2028 ms 2136 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2025 ms 2392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2052 ms 1372 KB Time limit exceeded
2 Halted 0 ms 0 KB -