@[w9095](/user/569235) 你再交一次?
by sz_jinzikai @ 2023-07-10 16:03:47
@[sz_jinzikai](/user/592476) [这里](https://www.luogu.com.cn/record/list?pid=P2403&user=569235)
by w9095 @ 2023-07-10 16:08:12
@[w9095](/user/569235) 你代码发一下
by sz_jinzikai @ 2023-07-10 16:10:12
@[w9095](/user/569235) 难道你打错了?
by sz_jinzikai @ 2023-07-10 16:12:28
@[sz_jinzikai](/user/592476)
```cpp
#include <bits/stdc++.h>
using namespace std;
struct edge
{
int v,next;
}e[300000],s[300000];
int n,r,c,u[300000],v[300000],t[300000],h[300000],sh[300000],dfn[300000],low[300000],st[300000],in[300000],scc[300000],q[300000],ind[300000],dis[300000],dh[300000],dl[300000],top=0,cnt=0,dfc=0,sc=0,ans=0;
int dx[8]={0,0,1,-1,1,1,-1,-1};
int dy[8]={1,-1,0,0,1,-1,1,-1};
unordered_map<pair<int,int>,int>hou;
void add_edge(int u,int v,struct edge e[],int h[])
{
e[++cnt].next=h[u];
e[cnt].v=v;
h[u]=cnt;
}
void tarjan(int now)
{
dfn[now]=low[now]=++dfc,st[++top]=now,in[now]=1;
for(int i=h[now];i;i=e[i].next)
if(!dfn[e[i].v])
{
tarjan(e[i].v);
low[now]=min(low[now],low[e[i].v]);
}
else if(in[e[i].v])
low[now]=min(low[now],dfn[e[i].v]);
if(dfn[now]==low[now])
{
sc++;
while(st[top]!=now)
scc[st[top]]=sc,q[sc]++,in[st[top]]=0,top--;
scc[st[top]]=sc,q[sc]++,in[st[top]]=0,top--;
}
}
void topo_sort()
{
int h=1,t=0,que[300000];
for(int i=1;i<=sc;i++)
if(ind[i]==0)dis[i]=q[i],que[++t]=i;
while(h<=t)
{
int now=que[h];
for(int i=sh[now];i;i=s[i].next)
{
dis[s[i].v]=max(dis[s[i].v],dis[now]+q[s[i].v]);
ind[s[i].v]--;
if(ind[s[i].v]==0)que[++t]=s[i].v;
}
h++;
}
}
int main()
{
scanf("%d%d%d",&n,&r,&c);
for(int i=1;i<=n;i++)
{
scanf("%d%d%d",&u[i],&v[i],&t[i]);
if(t[i]==1&&dh[u[i]]==0)dh[u[i]]=i;
if(t[i]==1&&dh[u[i]]!=0)add_edge(i,dh[u[i]],e,h);
if(t[i]==2&&dl[v[i]]==0)dl[v[i]]=i;
if(t[i]==2&&dl[v[i]]!=0)add_edge(i,dl[v[i]],e,h);
if(t[i]==3)hou[make_pair(u[i],v[i])]=i;
}
for(int i=1;i<=n;i++)
{
if(dh[u[i]]!=0)add_edge(dh[u[i]],i,e,h);
if(dl[v[i]]!=0)add_edge(dl[v[i]],i,e,h);
for(int j=0;j<8;j++)
if(hou[make_pair(u[i]+dx[j],v[i]+dy[j])]!=0)add_edge(hou[make_pair(u[i]+dx[j],v[i]+dy[j])],i,e,h);
}
for(int i=1;i<=n;i++)
if(!dfn[i])tarjan(i);
cnt=0;
for(int i=1;i<=n;i++)
for(int j=h[i];j;j=e[j].next)
if(scc[i]!=scc[e[j].v])ind[scc[e[j].v]]++,add_edge(scc[i],scc[e[j].v],s,sh);
topo_sort();
for(int i=1;i<=sc;i++)
ans=max(ans,dis[i]);
printf("%d",ans);
return 0;
}
```
by w9095 @ 2023-07-10 16:14:44
@[w9095](/user/569235) 哥我本地都编译不过。
by Aisaka_Taiga @ 2023-07-10 16:15:55
@[w9095](/user/569235) 那我布吉岛了
by sz_jinzikai @ 2023-07-10 16:16:57
@[w9095](/user/569235) 应该是umap不能套pair吧(?
by Aisaka_Taiga @ 2023-07-10 16:17:36
@[Aisaka_Taiga](/user/526519) 主要是,以前这个东西可以过的,现在不行了。这个东西是被删了吗?
[这里](https://www.luogu.com.cn/record/85932599)
by w9095 @ 2023-07-10 16:18:22
@[Aisaka_Taiga](/user/526519) 我试试
by w9095 @ 2023-07-10 16:18:53