比赛 2024国庆练习1 评测结果 AAAAAAAAAA
题目名称 宝藏 最终得分 100
用户昵称 ┭┮﹏┭┮ 运行时间 2.038 s
代码语言 C++ 内存使用 40.03 MiB
提交时间 2024-10-04 17:38:32
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 3e5+10;

ll read(){
	ll x = 0,f = 1;char c = getchar();
	for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
	for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
	return x * f;
}

int n,r,c;

map<pii,int>id;
int idx,is[N];
int lx[10] = {0,1,1,1,0,-1,-1,-1},ly[10] = {1,1,0,-1,-1,-1,0,1};
vector<int>e[N]; 


int cnt,top,num;
int siz[N],dfn[N],low[N],st[N],col[N];
bool v[N];
void tarjan(int x){
	dfn[x] = low[x] = ++cnt;
	st[++top] = x,v[x] = 1;
	for(int y : e[x]){
		if(!dfn[y])tarjan(y),low[x] = min(low[x],low[y]);
		else if(v[y])low[x] = min(low[x],dfn[y]);
	}
	if(dfn[x] == low[x]){
		int y = 0;num++;
		do{
			y = st[top--];
			col[y] = num,siz[num] += is[y];
			v[y] = 0;
		}while(y != x);
	}
}


int ru[N],ans,f[N];
map<pii,bool>ch; 
vector<int>e1[N];
void topsort(){
	queue<int>q; 
	for(int i = 1;i <= num;i++)
		if(!ru[i])q.push(i),f[i] = siz[i];
	while(!q.empty()){
		int x = q.front();q.pop();
		ans = max(ans,f[x]);
		for(int y : e1[x]){
			f[y] = max(f[y],f[x] + siz[y]);
			if(!(--ru[y]))q.push(y);
		}
	}
}

int li[1000010],he[1000010];
struct node{
	int x,y,op;
}a[N];
int main(){
	freopen("hzsotomon.in","r",stdin);
	freopen("hzsotomon.out","w",stdout);
	n = read(),r = read(),c = read();
	//r 行 c 列 
	for(int i = 1;i <= n;i++){
		int x = read(),y = read(),op = read();
		a[i] = {x,y,op};
		if(!he[x])he[x] = ++idx;
		if(!li[y])li[y] = ++idx; 
		if(!id[{x,y}])id[{x,y}] = ++idx,is[idx] = 1;
	}
	for(int i = 1;i <= n;i++){
		int x = a[i].x,y = a[i].y,op = a[i].op;
		int now = id[{x,y}];
		is[now] = 1;
		e[he[x]].pb(now),e[li[y]].pb(now);
		if(op == 1)e[now].pb(he[x]);
		else if(op == 2)e[now].pb(li[y]);
		else{
			for(int j = 0;j < 8;j++){
				int xx = x + lx[j],yy = y + ly[j];
				if(id[{xx,yy}])e[now].pb(id[{xx,yy}]);
			}
		} 
	}
	for(int i = 1;i <= idx;i++)
		if(!dfn[i])tarjan(i);
	for(int x = 1;x <= idx;x++){
		for(int y : e[x]){
			if(col[x] == col[y] || ch[{col[x],col[y]}])continue;
			e1[col[x]].pb(col[y]),ru[col[y]]++;
			ch[{col[x],col[y]}] = 1;
		}
	}
	topsort();
	printf("%d\n",ans);

	return 0;

}