Pagini recente » Cod sursa (job #1147839) | Cod sursa (job #986815) | Cod sursa (job #1949421) | Cod sursa (job #1977677) | Cod sursa (job #2543333)
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
const int DIM = (1 << 17);
int n, m, src, dst, x, y, z;
vector <pair <int, int>> g[250005];
bool viz[250005];
char nxt() {
static char buff[DIM];
static int bp = DIM;
if(bp == DIM) {
fread(buff, 1, DIM, stdin);
bp = 0;
}
return buff[bp++];
}
void read(int &x) {
static char ch;
x = 0;
do {
ch = nxt();
} while(ch < '0' || '9' < ch);
do {
x = x * 10 + ch - '0';
} while('0' <= ch && ch <= '9');
}
bool bfs(int lim) {
queue <int> q;
for(int i = 1; i <= n; i++)
viz[i] = 0;
viz[src] = 1;
q.push(src);
while(!q.empty()) {
int nod = q.front();
q.pop();
for(auto &fiu : g[nod]) {
if(fiu.second <= lim && !viz[fiu.first]) {
q.push(fiu.first);
viz[fiu.first] = 1;
}
}
}
return viz[dst];
}
int main() {
freopen("pscnv.in", "r", stdin);
freopen("pscnv.out", "w", stdout);
read(n), read(m), read(src), read(dst);
for(; m; m--) {
read(x), read(y), read(z);
g[x].push_back({y, z});
}
int st = 1, dr = 1000, mid;
while(st <= dr) {
mid = (st + dr) >> 1;
if(bfs(mid))
dr = mid - 1;
else
st = mid + 1;
}
printf("%d", st);
return 0;
}