104412024-04-02 17:02:31111Labirintuscpp17Forditási hiba
#include<bits/stdc++.h>
using namespace std;

#define int long long

struct DSU{
	vector<int>v;
	vector<pair<int,int>>s;
	
	DSU(){
	}
	
	DSU(int n):v(n,-1){
	}
	
	int find(int i){
		return v[i]<0?i:find(v[i]);
	}
	
	void unite(int a,int b){
		a=find(a);
		b=find(b);
		if(a==b){
			s.emplace_back(-1,-1);
			s.emplace_back(-1,-1);
			return;
		}
		if(a>b){
			swap(a,b);
		}
		s.emplace_back(a,v[a]);
		s.emplace_back(b,v[b]);
		v[a]+=v[b];
		v[b]=a;
	}
	
	void undo(){
		for(int i=0;i<2;i++){
			auto[a,aa]=s.back();
			s.pop_back();
			if(a!=-1){
				v[a]=aa;
			}
		}
	}
};

int R,C;
DSU d;

int x(int r,int c){
	return r*(C+1)+c;
}

void init_labyrinth(int R_,int C_,std::vector<std::vector<int>>L){
	R=R_,C=C_;
	d=DSU((R+1)*(C+1));
	for(int i=0;i+1<C;i++){
		d.unite(x(R,i),x(R,i+1));
	}
	for(int i=0;i+1<R;i++){
		d.unite(x(i,C),x(i+1,C));
	}
	for(int i=0;i<R;i++){
		for(int j=0;j<C;j++){
			if(L[i][j]){
				d.unite(x(i,j),x(i,j+1));
				d.unite(x(i,j),x(i+1,j));
				d.unite(x(i,j),x(i+1,j+1));
			}
		}
	}
}

bool can_escape(int N,std::vector<int>U,std::vector<int>V){
	for(int k=0;k<N;k++){
		int i=U[k],j=V[k];
		d.unite(x(i,j),x(i,j+1));
		d.unite(x(i,j),x(i+1,j));
		d.unite(x(i,j),x(i+1,j+1));
	}
	int ans=d.find(x(R,C-1))!=d.find(x(R-1,C));
	for(int k=0;k<N;k++){
		d.undo();
		d.undo();
		d.undo();
	}
	return ans;
}

#ifdef LOCAL
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int R,C,Q;
	cin>>R>>C>>Q;
	vector<vector<int>>L(R,vector<int>(C));
	for(int i=0;i<R;i++){
		for(int j=0;j<C;j++){
			char c;
			cin>>c;
			L[i][j]=c-'0';
		}
	}
	init_labyrinth(R,C,L);
	while(Q--){
		int N;
		cin>>N;
		vector<int>U(N),V(N);
		for(int i=0;i<N;i++){
			cin>>U[i]>>V[i];
		}
		cout<<can_escape(N,U,V)<<'\n';
	}
	return 0;
}
#endif
Forditási hiba
exit status 1
/usr/bin/ld: /tmp/cc5LL5nz.o: in function `main':
grader.cpp:(.text.startup+0x464): undefined reference to `init_labyrinth(int, int, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)'
/usr/bin/ld: grader.cpp:(.text.startup+0x769): undefined reference to `can_escape(int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status
Exited with error status 1