Pagini recente » Cod sursa (job #702301) | Cod sursa (job #2510308) | Cod sursa (job #623458) | Cod sursa (job #2118369) | Cod sursa (job #3145962)
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
ifstream in ("pscnv.in");
ofstream out ("pscnv.out");
const int max_size = 25e4 + 1;
struct str{
int x, y, c;
bool operator < (const str & aux) const
{
return c < aux.c;
}
};
int t[max_size];
vector <str> mc;
int rad (int x)
{
if (x == t[x])
{
return x;
}
return t[x] = rad(t[x]);
}
int main ()
{
int n, m, x, y;
in >> n >> m >> x >> y;
for (int i = 1; i <= n; i++)
{
t[i] = i;
}
while (m--)
{
int a, b, c;
in >> a >> b >> c;
mc.push_back({a, b, c});
}
sort(mc.begin(), mc.end());
for (auto f : mc)
{
if (rad(f.x) != rad(f.y))
{
t[rad(f.x)] = rad(f.y);
}
if (rad(x) == rad(y))
{
out << f.c;
exit(0);
}
}
in.close();
out.close();
return 0;
}