이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ve vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define si(v) (int)v.size()
#define en '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e5 + 228;
const int big = 1e9;
int n, k;
bool mrk[N];
vector<pi> g[N];
int dfs(int v, int dest, int st, int mxn){
if (v == dest){
return mxn - st;
}
mrk[v] = 1;
int mx = -big;
for (int i = 0; i < si(g[v]); i++){
int u = g[v][i].fi;
if (mrk[u]) continue;
mx = max(mx, dfs(u, dest, st + 1, max(mxn, g[v][i].se)));
}
return mx;
}
int main(){
iostream::sync_with_stdio(false); cin.tie(0); ios_base::sync_with_stdio(false); cout.tie(0);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
cin >> n >> k;
for (int i = 1; i <= n - 1; i++){
int a, b, x;
cin >> a >> b >> x;
g[a].pb(mp(b, x));
g[b].pb(mp(a, x));
}
int ans = 0;
for (int i = 1; i <= n; i++){
for (int j = i + 1; j <= n; j++){
//if (i == j) continue;
for (int i = 1; i <= n; i++) mrk[i] = 0;
int dans = dfs(i, j, 0, 0);
if (dans >= k) ans++;
//cout << i << '|' << j << '|' << dans << "|k=" << k << en;
}
}
cout << ans * 2;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |