Submission #364190

# Submission time Handle Problem Language Result Execution time Memory
364190 2021-02-08T11:11:04 Z b23v Tropical Garden (IOI11_garden) C++14
49 / 100
5000 ms 2028 KB
#include "garden.h"
#include "gardenlib.h"

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <climits>
#include <cstring>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using ii = pair<int,int>;
using vii = vector<pair<int,int>>;
using vb = vector<bool>;
template<typename T>
using Graph = vector<vector<T>>;

struct Node
{
	int v, i;
	bool operator< (const Node& a) const
	{
		return i < a.i;
	}
};

bool path(int u, int v, int k, const Graph<Node>& graph)
{
	int t = -1;
	while(k--)
	{
		if(graph[u][0].i == t && graph[u].size() > 1)
		{
			t = graph[u][1].i;
			u = graph[u][1].v;
		} else 
		{
			t = graph[u][0].i;
			u = graph[u][0].v;
		}
	}
	return u == v;
}

// self loops ?
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
	if(Q != 1) abort();

	Graph<Node> graph(N);
	for(int i = 0; i < M; ++i)
	{
		graph[R[i][0]].push_back(Node { R[i][1], i });
		graph[R[i][1]].push_back(Node { R[i][0], i });
	}
	for(auto x: graph) sort(x.begin(), x.end());

	int r = 0;
	for(int i = 0; i < N; ++i)
	{
		if(path(i, P, G[0], graph)) ++r;
	}
	answer(r);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 6 ms 364 KB Output is correct
11 Execution timed out 5067 ms 2028 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 6 ms 364 KB Output is correct
11 Execution timed out 5067 ms 2028 KB Time limit exceeded
12 Halted 0 ms 0 KB -