Cod sursa(job #2695958)

Utilizator vladdudauDudau Vlad vladdudau Data 14 ianuarie 2021 23:13:16
Problema PScNv Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.68 kb
#include <bitset>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>

using namespace std;

inline bool ifnum(char x){return (x>='0'&&x<='9');}

bitset <250001> b(0);
char ch[30];
struct node{int x,d;};
struct cmp_n{bool operator()(node x,node y){return x.d>y.d;};};
priority_queue <node,vector <node>,cmp_n> h;
vector <node> g[250001];

int main()
{
    int n,m,x,y,sol=0,a1,a2,a3,i,aux;
    vector <node>::iterator it;
    node auxn,auxn2;
    freopen("pscnv.in","r",stdin);
    freopen("pscnv.out","w",stdout);
    scanf("%d %d %d %d\n",&n,&m,&x,&y);
    for (;m;--m)
    {
        fgets(ch,sizeof(ch),stdin);
        aux=strlen(ch)-1;
        for (a1=0,i=0;i<aux;++i)
            if (ifnum(ch[i]))
                a1=a1*10+ch[i]-'0';
            else
                break;
        ++i;
        for (a2=0;i<aux;++i)
            if (ifnum(ch[i]))
                a2=a2*10+ch[i]-'0';
            else
                break;
        ++i;
        for (a3=0;i<aux;++i)
            if (ifnum(ch[i]))
                a3=a3*10+ch[i]-'0';
            else
                break;
        auxn.x=a2;
        auxn.d=a3;
        g[a1].push_back(auxn);
    }
    auxn.d=0;
    auxn.x=x;
    h.push(auxn);
    while (!h.empty())
    {
        auxn=h.top();
        b[auxn.x]=1;
        h.pop();
        if (auxn.d>sol)
            sol=auxn.d;
        if (auxn.x==y)
            break;
        for (it=g[auxn.x].begin();it!=g[auxn.x].end();++it)
            if (!b[it->x])
            {
                auxn2.x=it->x;
                auxn2.d=it->d;
                h.push(auxn2);
            }
    }
    printf("%d\n",sol);
    return 0;
}