Pagini recente » Cod sursa (job #1406302) | Cod sursa (job #1599637) | Cod sursa (job #1579326) | fmi-no-stress-2012/clasament | Cod sursa (job #617502)
Cod sursa(job #617502)
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
const int N = 250005;
vector <pair <int, int> > L[N];
int n, sup, S, D;
bool used[N];
char s[30];
bool cif(char ch) {
return '0' <= ch && ch <= '9';
}
void read() {
int m, x, y, p, poz;
scanf("%d%d%d%d", &n, &m, &S, &D);
for (int i = 1; i <= m; ++i) {
gets(s);
x = y = p = poz = 0;
while (cif(s[poz]))
x = x * 10 + s[poz] - '0', ++poz;
++poz;
while (cif(s[poz]))
y = y * 10 + s[poz] - '0', ++poz;
++poz;
while (cif(s[poz]))
p = p * 10 + s[poz] - '0', ++poz;
L[x].push_back(make_pair(y, p));
}
}
void df(int nod) {
used[nod] = 1;
for (int j = 0; j < (int)L[nod].size() && !used[D]; ++j)
if (!used[L[nod][j].first] && L[nod][j].second <= sup)
df(L[nod][j].first);
}
bool valid(int x) {
sup = x;
for (int i = 1; i <= n; ++i)
used[i] = 0;
df(S);
return used[D];
}
int cautb() {
int i = 0, pas = 1 << 10;
for (i = 0; pas; pas >>= 1)
if (!valid(i + pas))
i += pas;
return i + 1;
}
int main() {
freopen("pscnv.in", "r", stdin);
freopen("pscnv.out", "w", stdout);
read();
printf("%d", cautb());
return 0;
}