vector<PII> D[MAX]; //PII(id, w) int sum = 0, d[MAX]; //int p[MAX]; bool seen[MAX] = {false};
intmain(){ int V, E, s, t, w;
scanf("%d %d", &V, &E);
for (int i = 0; i < V; i++) { d[i] = INT_MAX; }
for (int i = 0; i < E; i++) { scanf("%d %d %d", &s, &t, &w); D[s].push_back(PII(t, w)); D[t].push_back(PII(s, w)); }
int ct = 0; s = 0; seen[0] = true;
while (ct < V - 1) { for (int i = 0; i < D[s].size(); i++) { t = D[s][i].first; w = D[s][i].second; if (!seen[t] && d[t] > w) { d[t] = w; // p[t] = u; } }
int min = 0; for (int i = 0; i < V; i++) if (!seen[i] && d[i] < d[min]) min = i;