Language: C

#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <queue>
#include <vector>
#include <cstring>
#include <iostream>
#include <map>
#define pb push_back
#define mp make_pair
using namespace std;
typedef vector<pair<int,int> >::iterator IT;
const int N = 30005;
int sz[N], fr[N], f[N], dis[N];
int opt[N];
bool vis[N];
bool del[N];
vector<int> all;
vector<pair<int,int> > inf, vv[N], vec[N];
void calc(int u, int par){
    all.pb(u);
    sz[u] = 1;
    opt[u] = 0;
    for(IT e = vec[u].begin(); e != vec[u].end(); ++e){
        if(!del[e->first] && e->first != par){
            calc(e->first, u);
            sz[u] += sz[e->first];
            opt[u] = max(opt[u], sz[e->first]);
        }
    }
}

int Center(int u){
    all.clear();
    calc(u, -1);
    int n = all.size(), mx = 1e9;
    for(vector<int>::iterator e = all.begin(); e != all.end(); ++e){
        opt[*e] = max(opt[*e], n-sz[*e]);
        if(opt[*e] < mx){
            mx = opt[*e];
            u = *e;
        }
    }
    return u;
}


void go(int u, int par, int dep, int len){
    if(dep > inf.size()) inf.pb(mp(len,1));
    else{
        if(len > inf[dep-1].first) inf[dep-1] = mp(len, 1);
            else if(len == inf[dep-1].first) inf[dep-1].second++;
    }
    for(IT e = vec[u].begin(); e != vec[u].end(); ++e){
        if(!del[e->first] && e->first != par){
            go(e->first, u, dep+1, len+e->second);
        }
    }
}
pair<int,int> M[N];
int k, ans, ansc;
void dfs(int u){
    u = Center(u);
    //M.clear();
    for(int i=0;i<=all.size();++i) M[i]=mp(0,0);
    for(IT e = vec[u].begin(); e != vec[u].end(); ++e){
        if(!del[e->first]){
            inf.clear();
            go(e->first, u, 1, e->second);
            for(int p = 0; p < inf.size(); ++p){
                if(M[k-1-p].first){
                    if(M[k-1-p].first + inf[p].first > ans){
                        ans = M[k-1-p].first + inf[p].first;
                        ansc = M[k-1-p].second*inf[p].second;
                    }
                    else if(M[k-1-p].first+inf[p].first == ans){
                        ansc += M[k-1-p].second*inf[p].second;
                    }
                }
            }
            for(int p = 0; p < inf.size(); ++p){
                if(inf[p].first == M[p+1].first) M[p+1].second += inf[p].second;
                else if(inf[p].first > M[p+1].first) M[p+1] = inf[p];
            }
        }
    }

    if(M[k].first > ans){
        ans = M[k].first;
        ansc = M[k].second;
    }
    else
    if(M[k].first == ans){
        ansc += M[k].second;
    }

    del[u] = true;
    for(IT e = vec[u].begin(); e != vec[u].end(); ++e){
        if(!del[e->first])
        dfs(e->second);
    }


}

void build(){
    queue<int> q;
    q.push(1);
    memset(vis,0,sizeof(vis));
    memset(dis,0x1f,sizeof(dis));
    dis[1] = 0;
    while(!q.empty()){
        int u = q.front();
        q.pop();
        vis[u] = 0;
        for(IT e = vv[u].begin(); e != vv[u].end(); ++e){
            if(dis[u]+e->second < dis[e->first] || (dis[u]+e->second == dis[e->first] && u < f[e->first])){
                dis[e->first] = dis[u] + e->second;
                f[e->first] = u;
                fr[e->first] = e->second;
                if(!vis[e->first]){
                    vis[e->first] = true;
                    q.push(e->first);
                }
            }
        }
    }
}

void build(){
    priority_queue<pair<int,int> > q;
    q.push(mp(0, 1));
    memset(vis,0,sizeof(vis));
    memset(dis,0x1f,sizeof(dis));
    dis[1] = 0;
    while(!q.empty()){
    }
}

int main(){
    int tt, n, m, i, a, b, c;
    scanf("%d",&tt);
    while(tt--){
        memset(del,0,sizeof(del));
        scanf("%d%d%d",&n,&m,&k);
        k--;
        for(i=1;i<=n;++i) vv[i].clear(), vec[i].clear();
        for(i=1;i<=n;++i){
            scanf("%d%d%d",&a,&b,&c);
            vv[a].pb(mp(b, c));
            vv[b].pb(mp(a, c));
        }
        build();
        for(i=2;i<=n;++i){
            vec[f[i]].pb(mp(i, fr[i]));
            vec[i].pb(mp(f[i], fr[i]));
        }
        ans = 0;
        dfs(1);
        printf("%d %d\n", ans, ansc);
    }
    return 0;
}

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