답안 #333709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
333709 2020-12-07T14:11:07 Z LucaDantas Meetings (JOI19_meetings) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
// #include "meetings.h"
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma")  

#include "meetings.h"
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <utility>
#include <vector>

namespace {

const int MAX_N = 2000;
const int MAX_CALLS = 100000;

void WrongAnswer(int code) {
	printf("Wrong Answer [%d]\n", code);
	exit(0);
}

int N, num_calls;
std::vector<int> graph[MAX_N];
std::set<std::pair<int, int>> edges, edges_reported;

int weight[MAX_N];

bool Visit(int p, int e, int rt = -1) {
	if (p == e) {
		++weight[p];
		return true;
	}
	for (int q : graph[p]) {
		if (q != rt) {
			if (Visit(q, e, p)) {
				++weight[p];
				return true;
			}
		}
	}
	return false;
}

}	// namespace

int Query(int u, int v, int w) {
	if (!(0 <= u && u <= N - 1 && 0 <= v && v <= N - 1 && 0 <= w && w <= N - 1 &&
			u != v && u != w && v != w)) {
		WrongAnswer(1);
	}
	if (++num_calls > MAX_CALLS) {
		WrongAnswer(2);
	}
	std::fill(weight, weight + N, 0);
	Visit(u, v);
	Visit(u, w);
	Visit(v, w);
	for (int x = 0; x < N; ++x) {
		if (weight[x] == 3) {
			return x;
		}
	}
	printf("Error: the input may be invalid\n");
	exit(0);
}

void Bridge(int u, int v) {
	// printf("%d %d\n", u, v);
	if (!(0 <= u && u < v && v <= N - 1)) {
		WrongAnswer(3);
	}
	if (!(edges.count(std::make_pair(u, v)) >= 1)) {
		WrongAnswer(4);
	}
	if (!(edges_reported.count(std::make_pair(u, v)) == 0)) {
		WrongAnswer(5);
	}
	edges_reported.insert(std::make_pair(u, v));
}

int main() {
	if (scanf("%d", &N) != 1) {
		fprintf(stderr, "Error while reading input\n");
		exit(1);
	}
	for (int i = 0; i < N - 1; ++i) {
		int u, v;
		if (scanf("%d%d", &u, &v) != 2) {
			fprintf(stderr, "Error while reading input\n");
			exit(1);
		}
		graph[u].push_back(v);
		graph[v].push_back(u);
		edges.insert(std::make_pair(u, v));
	}

	num_calls = 0;
	Solve(N);
	if (edges_reported.size() != static_cast<size_t>(N - 1)) {
		WrongAnswer(6);
	}
	printf("Accepted: %d\n", num_calls);
	return 0;
}


#define pb push_back
#define sz(a) (a).size()

std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count() ^ (long long) (make_unique<char>().get()));

constexpr int maxn = 2e3+10;

void solve(vector<int>& a) {
	shuffle(a.begin(), a.end(), rng);
	if(sz(a) <= 1) return;
	if(sz(a) == 2) return (void)(Bridge(min(a[0], a[1]), max(a[0], a[1])));
	int divide = Query(a[0], a[1], a[2]);
	vector<int> head;
	if(divide == a[0]) head.pb(a[1]);
	else head.pb(a[0]);
	vector<vector<int>> grp;
	map<int,int> id;
	id[head[0]] = 0;
	grp.pb({head[0]});
	for(int x : a) {
		if(x != divide) {
			bool ok = 0;
			for(int y : head) {
				if(x != y) {
					if(Query(divide, x, y) != divide)
						ok = 1, grp[id[y]].pb(x);
				} else ok = 1;
			}
			if(!ok) id[x] = sz(head), head.pb(x), grp.pb({x});
		}
	}
	for(int y : head) {
		int top = y;
		for(int x : grp[id[y]])
			if(x != top)
				top = Query(divide, x, top);
		Bridge(min(divide, top), max(divide, top));
		solve(grp[id[y]]);
	}
}

void Solve(int n) {
	vector<int> a;
	for(int i = 0; i < n; i++)
		a.pb(i);
	solve(a);
}

Compilation message

/tmp/ccrmf4ia.o: In function `Query(int, int, int)':
grader.cpp:(.text+0x110): multiple definition of `Query(int, int, int)'
/tmp/ccqlhkRP.o:meetings.cpp:(.text+0x110): first defined here
/tmp/ccrmf4ia.o: In function `Bridge(int, int)':
grader.cpp:(.text+0x240): multiple definition of `Bridge(int, int)'
/tmp/ccqlhkRP.o:meetings.cpp:(.text+0x300): first defined here
/tmp/ccrmf4ia.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccqlhkRP.o:meetings.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status