文件目录

#include <bits/stdc++.h>
using namespace std;
int n, x, a, b;
int num[105];
int m[105][105];
bool vis[105];
int dfs(int i, int c)
{
    int ans = num[i] * c;
    for (int j = 1; j <= n; j++)
        if (m[i][j] && vis[j] == false)
        {
            vis[j] = true;
            ans += dfs(j, c + 1);
        }
    return ans;
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> x >> a >> b;
        num[i] = x;
        m[i][b] = m[b][i] = 1;
        m[i][a] = m[a][i] = 1;
    }
    int ans = 999999999;
    for (int i = 1; i <= n; i++)
    {
        fill(vis, vis + 105, false);
        vis[i] = true;
        ans = min(ans, dfs(i, 0));
    }
    cout << ans;
    return 0;
}