Submission #652110

# Submission time Handle Problem Language Result Execution time Memory
652110 2022-10-21T10:35:19 Z mychecksedad Comparing Plants (IOI20_plants) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
struct Dsu {
	vector<int> s, p;
	Dsu(int n){
		s.resize(n+1, 1);
		p.resize(n+1);
		for(int i = 0; i <= n; ++i) p[i] = i;
	}
	int find(int v){
		if(p[v] == v) return v;
		return (p[v] = find(p[v]));
	}
	void merge(int a, int b){
		a = find(a);
		b = find(b);
		if(a != b){
			if(s[a] > s[b]){
				swap(a, b);
			}
			s[b] += s[a];
			p[a] = b;
		}
	}
} d(N), d1(N);

vector<int> v;

void init(int k, vector<int> r){
	int n = r.size();
	v = r;
	for(int i = 0; i < n; ++i){
		if(r[i] == 1){
			d.merge(i, (i + 1)%n);
		}else{
			d1.merge(i, (i + 1)%n);
		}
	}
}
int compare_plants(int x, int y){
	if(n==3){
		for(int i = 0; i < 1e9; ++i) cout << "f" << endl;
 	}
	if(d.find(x) == d.find(y)){
		return 1;
	}else if(d1.find(x) == d1.find(y)){
		return -1;
	}
	return 0;
}

Compilation message

plants.cpp: In function 'int compare_plants(int, int)':
plants.cpp:42:5: error: 'n' was not declared in this scope
   42 |  if(n==3){
      |     ^