Language: C

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <bitset>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define FI first
#define SE second
#pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
const int maxn=3e4+5;
int head[maxn];
struct Edge
{
    int next,to,len;
}ed[maxn*4];
int ecnt;
int n,m,K;

inline void addedge(int u,int v,int c)
{
    ed[ecnt].next=head[u];
    ed[ecnt].to=v;
    ed[ecnt].len=c;
    head[u]=ecnt++;
}

int dis[maxn],pre[maxn],prelen[maxn];
bool ok[maxn];
struct node
{
    int u,dis,pre;
    inline node() {}
    inline node(int _u,int _dis,int _pre)
    {
        u=_u; dis=_dis; pre=_pre;
    }
    bool operator <(const node &a)const
    {
        return dis>a.dis||(dis==a.dis&&pre>a.pre);
    }
};
priority_queue <node> Q;

inline void Dijkstra(int S)
{
    memset(ok,0,(n+3)*sizeof(bool));
    memset(dis,0x3f,(n+3)*sizeof(int));
    memset(pre,0x3f,(n+3)*sizeof(int));
    dis[S]=0;
    Q.push(node(S,0,S));
    node t;
    while(!Q.empty())
    {
        t=Q.top(); Q.pop();
        int u=t.u;
        if(ok[u]) continue;
        ok[u]=1;
        for(int e=head[u];~e;e=ed[e].next)
        {
            int v=ed[e].to;
            if(dis[v]>dis[u]+ed[e].len)
            {
                dis[v]=dis[u]+ed[e].len;
                pre[v]=u;
                prelen[v]=ed[e].len;
                Q.push(node(v,dis[v],u));
            }
            else if(dis[v]==dis[u]+ed[e].len)
            {
                if(pre[v]>u)
                {
                    pre[v]=u;
                    prelen[v]=ed[e].len;
                }
            }
        }
    }
}

inline void build_tree()
{
    memset(head,-1,(n+3)*sizeof(int));
    ecnt=0;
    for(int i=2;i<=n;++i)
    {
        addedge(pre[i],i,prelen[i]);
        addedge(i,pre[i],prelen[i]);
    }
}

bool done[maxn];
int sz[maxn],msz[maxn],tr[maxn],tot;
void get_size(int u,int fa)
{
    sz[u]=1; msz[u]=1;
    tr[tot++]=u;
    for(int e=head[u];~e;e=ed[e].next)
    {
        int v=ed[e].to;
        if(v==fa||done[v]) continue;
        get_size(v,u);
        sz[u]+=sz[v];
        msz[u]=max(msz[u],sz[v]);
    }
}

inline int Findroot(int u)
{
    tot=0;
    get_size(u,u);
    int root,mz=INF;
    for(int i=0;i<tot;++i)
    {
        int v=tr[i];
        v=max(msz[v],sz[u]-sz[v]);
        if(v<mz)
        {
            mz=v;
            root=tr[i];
        }
    }
    return root;
}

int dep[maxn],f[maxn],g[maxn];
void get_dep(int u,int fa)
{
    dep[u]=0;
    for(int e=head[u];~e;e=ed[e].next)
    {
        int v=ed[e].to;
        if(v==fa||done[v]) continue;
        get_dep(v,u);
        dep[u]=max(dep[u],dep[v]);
    }
    ++dep[u];
}

int fc[maxn],gc[maxn];
void get_f(int u,int fa,int cnt,int dis)
{
    if(f[cnt]<dis)
    {
        f[cnt]=dis;
        fc[cnt]=1;
    }
    else if(f[cnt]==dis) ++fc[cnt];
    for(int e=head[u];~e;e=ed[e].next)
    {
        int v=ed[e].to;
        if(v==fa||done[v]) continue;
        get_f(v,u,cnt+1,dis+ed[e].len);
    }
}

struct Node
{
    int v,d;
}po[maxn];
inline bool cmp(Node a,Node b)
{
    return dep[a.v]<dep[b.v];
}

int max_len;
LL max_cnt;
void solve1(int u)
{
    int tot=0;
    for(int e=head[u];~e;e=ed[e].next)
    {
        int v=ed[e].to;
        if(done[v]) continue;
        get_dep(v,u);
        po[tot].v=v; po[tot++].d=ed[e].len;
    }
    sort(po,po+tot,cmp);
    memset(g,0,(dep[po[tot-1].v]+3)*sizeof(int));
    int pre=0;
    for(int i=0;i<tot;++i)
    {
        int v=po[i].v;
        memset(f,0,(dep[v]+3)*sizeof(int));
        get_f(v,u,1,po[i].d);
        int can=K-1;
        for(int j=0;j<=dep[v];++j)
        {
            if(j>can) break;
            if(can-j<=pre) max_len=max(max_len,f[j]+g[can-j]);
        }
        for(int j=0;j<=dep[v];++j) g[j]=max(g[j],f[j]);
        pre=dep[v];
    }
    done[u]=1;
    for(int e=head[u];~e;e=ed[e].next)
    {
        int v=ed[e].to;
        if(done[v]) continue;
        solve1(Findroot(v));
    }
}

void solve2(int u)
{
    int tot=0;
    for(int e=head[u];~e;e=ed[e].next)
    {
        int v=ed[e].to;
        if(done[v]) continue;
        get_dep(v,u);
        po[tot].v=v; po[tot++].d=ed[e].len;
    }
    sort(po,po+tot,cmp);
    memset(g,0,(dep[po[tot-1].v]+3)*sizeof(int));
    gc[0]=1;
    int pre=0;
    for(int i=0;i<tot;++i)
    {
        int v=po[i].v;
        memset(f,0,(dep[v]+3)*sizeof(int));
        get_f(v,u,1,po[i].d);
        fc[0]=1;
        int can=K-1;
        for(int j=1;j<=dep[v];++j)
        {
            if(j>can) break;
            if(can-j<=pre)
            {
                if(f[j]+g[can-j]==max_len) max_cnt+=fc[j]*gc[can-j];
            }
        }
        for(int j=1;j<=dep[v];++j)
        {
            if(g[j]<f[j])
            {
                g[j]=f[j];
                gc[j]=fc[j];
            }
            else if(g[j]==f[j]) gc[j]+=fc[j];
        }
        pre=dep[v];
    }
    done[u]=1;
    for(int e=head[u];~e;e=ed[e].next)
    {
        int v=ed[e].to;
        if(done[v]) continue;
        solve2(Findroot(v));
    }
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d",&n,&m,&K);
        memset(head,-1,(n+3)*sizeof(int));
        ecnt=0;
        while(m--)
        {
            int u,v,c;
            scanf("%d%d%d",&u,&v,&c);
            addedge(u,v,c);
            addedge(v,u,c);
        }
        Dijkstra(1);
        build_tree();
        max_len=0;
        memset(done,0,(n+3)*sizeof(bool));
        solve1(Findroot(1));
        max_cnt=0;
        memset(done,0,(n+3)*sizeof(bool));
        solve2(Findroot(1));
        printf("%d %I64d\n",max_len,max_cnt);
    }
    return 0;
}

Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.