diff --git a/HDOJ/5870_fzmh.cpp b/HDOJ/5870_fzmh.cpp new file mode 100644 index 0000000..68207fb --- /dev/null +++ b/HDOJ/5870_fzmh.cpp @@ -0,0 +1,152 @@ +#include +#include +#include +#include +#include +#define mp make_pair +#define pb push_back +#define fi first +#define sc second +using namespace std; +const int N = 201010; +const int M = 2010101; +const int inf = 2100000000; +typedef pair P; +priority_queue,greater

> Q; +int n,m,i,a,b,c,dis[N],cnt[N],dis1[N],cnt1[N],dis2[N],cnt2[N],X; +int id[N],ID[N],Id[N]; +vector

e[N]; +void gao(int x) +{ + int i; + for (i=1;i<=n;i++) + dis[i]=inf,cnt[i]=0; + dis[x]=0; + cnt[x]=1; + Q.push(mp(0,x)); + while (!Q.empty()) + { + P tmp=Q.top(); + Q.pop(); + x=tmp.sc; + if (dis[x]!=tmp.fi) continue; + for (i=0;iX) cnt[e[x][i].fi]=X; + } + } +} + +int ls[M],rs[M],s[M],tot,root[N]; +void build(int &x,int a,int b) +{ + x=++tot; + ls[x]=rs[x]=s[x]=0; + if (b-a>1) + { + int m=(a+b)>>1; + build(ls[x],a,m); + build(rs[x],m,b); + } +} +void insert(int y,int &x,int a,int b,int l,int r) +{ + x=++tot; + ls[x]=ls[y];rs[x]=rs[y];s[x]=s[y]+1; + if ((a<=l)&&(r<=b)) + return; + int m=(l+r)>>1; + if (a>1,ans=0; + if (acnt2[b]; +} +int main() +{ + while (~scanf("%d%d",&n,&m)) + { + if (n+m==0) return 0; + for (i=1;i<=n;i++) e[i].clear(); + scanf("%d",&X); + for (i=1;i<=m;i++) + { + scanf("%d%d%d",&a,&b,&c); + e[a].pb(mp(b,c)); + e[b].pb(mp(a,c)); + } + gao(1); + for (i=1;i<=n;i++) + dis1[i]=dis[i],cnt1[i]=cnt[i]; + gao(n); + for (i=1;i<=n;i++) + dis2[i]=dis[i],cnt2[i]=cnt[i]; + + tot=0; + build(root[0],0,n); + for (i=1;i<=n;i++) + id[i]=i; + sort(id+1,id+1+n,cmp); + for (i=1;i<=n;i++) + ID[id[i]]=i; + + for (i=1;i<=n;i++) + Id[i]=i; + sort(Id+1,Id+1+n,CMP); + for (i=1;i<=n;i++) + insert(root[i-1],root[i],ID[Id[i]]-1,ID[Id[i]],0,n); + long long ans=0; + for (i=1;i<=n;i++) + { + int l=1,r=n; + while (l<=r) + { + m=(l+r)>>1; + if (dis2[id[m]]+dis1[i]+1<=dis1[n]) l=m+1;else r=m-1; + } + int j=r; + + l=1;r=n; + while (l<=r) + { + m=(l+r)>>1; + if (1LL*cnt1[i]*cnt2[Id[m]]>=X) l=m+1;else r=m-1; + } + + if (j) ans=ans+query(root[r],0,j,0,n); + + + for (int k=0;k=X) ans--; + + if (dis1[i]+dis2[i]+1<=dis1[N]) + if (1LL*cnt1[i]*cnt2[i]>=X) ans--; + + } + printf("%lld\n",ans); + } +}