Pagini recente » Cod sursa (job #2615451) | Cod sursa (job #454647) | Cod sursa (job #234566) | Cod sursa (job #2502122) | Cod sursa (job #97163)
Cod sursa(job #97163)
#include <cstdio>
const int maxn = 250001;
FILE *in = fopen("pscnv.in","r"), *out = fopen("pscnv.out","w");
struct graf
{
int nod;
short cost;
graf *next;
};
int n, m, x, y;
graf *a[maxn];
void add(int to, int nod, short cost)
{
graf *q = new graf;
q->next = a[to];
q->nod = nod;
q->cost = cost;
a[to] = q;
}
void read()
{
fscanf(in, "%d %d %d %d", &n, &m, &x, &y);
int p, q;
short c;
for ( int i = 1; i <= m; ++i )
{
fscanf(in, "%d %d %hd", &p, &q, &c);
if ( p != q )
add(p, q, c);
}
}
struct tail
{
int nod;
tail *next;
};
//char viz[maxn];
int check(int k)
{
tail *p = new tail;
tail *u = new tail;
char viz[maxn] = {0};
p->next = NULL;
p->nod = x;
u = p;
while ( p )
{
graf *q = a[ p->nod ];
while ( q )
{
if ( !viz[q->nod] && q->cost <= k )
{
tail *t = new tail;
t->next = NULL;
t->nod = q->nod;
u->next = t;
u = t;
if ( u->nod == y )
return 1;
viz[u->nod] = 1;
}
q = q->next;
}
tail *t = p;
p = p->next;
delete t;
}
return 0;
}
int main()
{
read();
for ( int i = 1; i <= 1000; ++i )
if ( check(i) )
{
fprintf(out, "%d\n", i);
return 0;
}
return 0;
}