제출 #364190

#제출 시각아이디문제언어결과실행 시간메모리
364190b23v열대 식물원 (Tropical Garden) (IOI11_garden)C++14
49 / 100
5067 ms2028 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...