提问:HDU1301(Jungle Roads)WA了,题解也看了,但还是不知道为什么(c++)

提问:HDU1301(Jungle Roads)WA了,题解也看了,但还是不知道为什么(c++)

# include <bits/stdc++.h>

# define old_six \
    ios::sync_with_stdio (0);\
    \
    cin.tie (0);\
    \
    cout.tie (0);

# define ffor(i,name) \
    for (auto i = name.begin (); i != name.end (); i ++)

# define iter(type) \
    type :: iterator

using namespace std;

typedef long long ll;

typedef pair <int, int> pii;

typedef pair <ll, ll> pll;

using namespace std;

struct node {

    int a, b, c;

    bool operator < (const node& x) const {

        return c < x.c;

    }

} ;

int n, x, m, sum, f[30];

char a, b;

vector <node> v;

int find (int x) {

    return x == f[x] ? x : f[x] = find (f[x]);

}

int main () {

    old_six

    while (cin >> n, n) {

        v.clear ();

        sum = 0;

        for (int i = 1; i < 26; i ++)
            f[i] = i;

        while (-- n) {

            cin >> a >> m;

            while (m --)
                cin >> b >> x, v.push_back ({a - 'A', b - 'A', x});

        }

        sort (v.begin (), v.end ());

        for (size_t i = 0; i < v.size (); i ++)
            if (find (v[i].a) != find (v[i].b)) {

                f[f[v[i].a]] = f[v[i].b];

                sum += v[i].c;

            }

        cout << sum << '\n';

    }

    return 0;

}