正解:灭绝树。
mdzz倍增lca的根节点深度必须是1。。我因为这个错误调了好久。
我们考虑先求最短路,求完最短路以后,我们就能对原来的无向图构造一个DAG。当我们构造完DAG以后,我们要求的东西已经很明显。那就是删掉一个点以后,最多有多少个点与S不连通。那么,我们按照套路,将DAG跑一遍拓扑排序,建出灭绝树。然后求出除了S点以外的最大size就行了。
//It is made by wfj_2048~
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define inf (1LL<<60)
#define M (300010)
#define N (200010)
#define il inline
#define RG register
#define ll long long
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout) using namespace std; struct edge{ int nt,to; ll dis; }g[*M],g1[*M],g2[*M]; int head[N],head1[N],head2[N],q[*N],d[N],vis[N],dep[N],sz[N],f[][N],S,n,m,num,num1,num2,ans;
ll dis[N]; il int gi(){
RG int x=,q=; RG char ch=getchar(); while ((ch<'' || ch>'') && ch!='-') ch=getchar();
if (ch=='-') q=-,ch=getchar(); while (ch>='' && ch<='') x=x*+ch-,ch=getchar(); return q*x;
} il void insert(RG int from,RG int to,RG ll dis){ g[++num]=(edge){head[from],to,dis},head[from]=num; return; } il void insert1(RG int from,RG int to){ g1[++num1]=(edge){head1[from],to},head1[from]=num1; return; } il void insert2(RG int from,RG int to){ g2[++num2]=(edge){head2[from],to},head2[from]=num2; return; } il void spfa(RG int S){
for (RG int i=;i<=n;++i) dis[i]=inf;
RG int h=,t=; dis[S]=,vis[S]=,q[t]=S;
while (h<t){
RG int x=q[++h];
for (RG int i=head[x],v=g[i].to;i;i=g[i].nt,v=g[i].to)
if (dis[v]>dis[x]+g[i].dis){
dis[v]=dis[x]+g[i].dis;
if (!vis[v]) vis[v]=,q[++t]=v;
}
vis[x]=;
}
return;
} il void dfs1(RG int x){
vis[x]=;
for (RG int i=head[x],v=g[i].to;i;i=g[i].nt,v=g[i].to)
if (dis[v]==dis[x]+g[i].dis){
insert1(x,v),insert2(v,x),d[v]++;
if (!vis[v]) dfs1(v);
}
return;
} il void dfs2(RG int x){
sz[x]=; RG int v;
for (RG int i=head[x];i;i=g[i].nt)
v=g[i].to,dfs2(v),sz[x]+=sz[v];
if (x!=S) ans=max(ans,sz[x]); return;
} il int lca(RG int u,RG int v){
if (u==v) return u; if (dep[u]<dep[v]) swap(u,v);
for (RG int i=;i>=;--i)
if (dep[f[i][u]]>=dep[v]) u=f[i][u];
if (u==v) return u;
for (RG int i=;i>=;--i)
if (f[i][u]!=f[i][v]) u=f[i][u],v=f[i][v];
return f[][u];
} il void topsort(){
RG int h=,t=; q[t]=S,dep[S]=; //不赋初值会跪烂!!!
while (h<t){
RG int x=q[++h],v;
for (RG int i=head1[x];i;i=g1[i].nt){
v=g1[i].to,d[v]--;
if (!d[v]){
q[++t]=v; RG int Lca=;
for (RG int j=head2[v];j;j=g2[j].nt)
if (!Lca) Lca=g2[j].to; else Lca=lca(Lca,g2[j].to);
insert(Lca,v,),f[][v]=Lca,dep[v]=dep[Lca]+;
for (RG int j=;j<=;++j) f[j][v]=f[j-][f[j-][v]];
}
}
}
return;
} il void work(){
n=gi(),m=gi(),S=gi();
for (RG int i=,u,v,w;i<=m;++i){
u=gi(),v=gi(),w=gi();
insert(u,v,(ll)w),insert(v,u,(ll)w);
}
spfa(S); dfs1(S); memset(head,,sizeof(head)),num=;
topsort(); dfs2(S); printf("%d\n",ans); return;
} int main(){
File("757F");
work();
return ;
}