QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#305359#6335. Belt Conveyordanielkou5855Compile Error//C++173.2kb2024-01-15 09:05:592024-01-15 09:05:59

Judging History

你现在查看的是最新测评结果

  • [2024-01-15 09:05:59]
  • 评测
  • [2024-01-15 09:05:59]
  • 提交

answer

// Source: https://usaco.guide/general/io

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <bitset>

#define int long long
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()

using namespace std;

const int inf = (int) 1e18;

vector<vector<pair<int, int>>> adj;

vector<int> idx, parent, edge_idx;

void dfs(int c, int p, int e) {
	parent[c] = p;
	edge_idx[c] = e;

	for (auto n : adj[c]) {
		if (n.first != p) {
			idx[n.first] = (idx[c] + 1) % 3;
			dfs(n.first, c, n.second);
		}
	}
}

pair<int, int> combine(const pair<int, int> &a, const pair<int, int> b) {
	if (b.first > a.first) {
		return b;
	}

	return a;
}

void Solve(int N, vector<int> arr, vector<int> brr) {
	for (int i = 0; i < sz(arr); i++) {
		adj[arr[i]].push_back({brr[i], i});
		adj[brr[i]].push_back({arr[i], i});
	}

	for (int i = 0; i < N; i++) {
		// start from leaf
		if (sz(adj[i]) == 1) {
			dfs(i, -1, -1); break;
		}
	}

	vector<int> ans(N, inf); // inf means don't know

	while (true) {
		vector<int> ct(3, 0);

		pair<int, int> best = {0, 0};

		for (int i = 0; i < N; i++) {
			int tmp = 0;

			for (auto n : adj[i]) {
				tmp |= (ans[n.second] == inf);
			}

			ct[idx[i]] += tmp;

			best = combine(best, make_pair(ct[idx[i]], idx[i]));
		}

		// query
		vector<int> xrr(N - 1, 0), yrr(N, 0);

		for (int i = 0; i < N; i++) {
			if (idx[i] == best.second) {
				yrr[i] = 1;
			}
		}

    	for (int i = 0; i < N; i++) {
      		if (yrr[i]) {
        		for (auto n : adj[i]) {
          			if (ans[n.second] == 0 && arr[n.second] == i) {
						xrr[n.second] = 1;
					}

          			if (ans[n.second] == 1 && brr[n.second] == i) {
						xrr[n.second] = 1;
					}
        		}
      		}
    	}

		vector<int> query = Query(xrr, yrr);

		for (int i = 0; i < N; i++) {
			if (!yrr[i]) {
				continue;
			}

			if (query[i]) {
				for (auto n : adj[i]) {
					if (xrr[n.second]) { // reversed
						if (n.first == brr[n.second]) {
							// a -> b reversed (b -> a) doesn't work
							ans[n.second] = 0;
						} else {
							// b -> a reversed (a -> b) doesn't work
							ans[n.second] = 1;
						}
					} else {
						// not reversed
						if (n.first == brr[n.second]) {
							// a -> b normal doesn't work
							ans[n.second] = 1;
						} else {
							// b -> a normal doesn't work
							ans[n.second] = 0;
						}
					}
				}
			} else {
				for (auto n : adj[i]) {
					if (query[n.first]) {
						if (xrr[n.second]) { // reversed
							if (n.first == brr[n.second]) {
								// a -> b reversed (b -> a) works
								ans[n.second] = 1;
							} else {
								// b -> a reversed (a -> b) works
								ans[n.second] = 0;
							}
						} else { // not reversed
							if (n.first == brr[n.second]) {
								// a -> b normal works
								ans[n.second] = 0;
							} else {
								// b -> a normal works
								ans[n.second] = 1;
							}
						}
					}
				}
			}
		}

		bool good = true;

		for (int i = 0; i < N - 1; i++) {
			if (ans[i] == inf) {
				good = false; break;
			}
		}

		if (good) {
			break;
		}
	}

	Answer(ans);
}

Details

answer.code: In function ‘void Solve(long long int, std::vector<long long int>, std::vector<long long int>)’:
answer.code:99:37: error: ‘Query’ was not declared in this scope; did you mean ‘query’?
   99 |                 vector<int> query = Query(xrr, yrr);
      |                                     ^~~~~
      |                                     query
answer.code:165:9: error: ‘Answer’ was not declared in this scope
  165 |         Answer(ans);
      |         ^~~~~~