Hi fellows!
3502 - "The Mysterious X Network" - classical BFS, as it seems, but MLE.
Considering timings in its ranklist it's a tough question (best is ~2 sec), so I need some hints.
Thank you.
Moderator: Board moderators
serur wrote:Hi fellows!
3502 - "The Mysterious X Network" - classical BFS, as it seems, but MLE.
Considering timings in its ranklist it's a tough question (best is ~2 sec), so I need some hints.
Thank you.
serur wrote:Hi fellows!
3502 - "The Mysterious X Network" - classical BFS, as it seems, but MLE.
Considering timings in its ranklist it's a tough question (best is ~2 sec), so I need some hints.
Thank you.
#include <stdio.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <cmath>
#include <queue>
using namespace std;
typedef long long LL; typedef vector<int> VI; typedef pair<int,int> PI;
typedef vector<PI>VPI; typedef set<int>SI; typedef map<int,int>MI;
typedef queue<int> QI;
const int INF = 2100000000;
#define PRNUM(zm) printf("%d\n",zm)
#define NL() printf("\n")
#define MAX(zm1,zm2) (zm1>=zm2 ? zm1 : zm2)
#define MIN(zm1,zm2) (zm1<=zm2 ? zm1 : zm2)
#define FOREACH(zm,r_kont,kont) for(r_kont::iterator (zm)=(kont).begin();(zm)!=(kont).end();++(zm))
#define REP(zm,m) for(int licznikmax=(m),(zm)=0;(zm)<licznikmax;++(zm))
#define FOR(zm,start,m) for(int licznikmax=(m),(zm)=(start);(zm)<=licznikmax;++(zm))
#define FORD(zm,m) for(int (zm)=m;(zm)>=0;--(zm))
#define ALL(zm) zm.begin(),zm.end()
int Zest,N1,M1,K1,L1,L2,L3;
const int IleL=100010;
vector<int>V[IleL];
int B[IleL];
int main(int argc, char* argv[])
{
freopen("pl.txt","r",stdin);
scanf("%d",&Zest);
FOR(ZNR,1,Zest)
{
scanf("%d",&L1);
REP(a,L1)
{
// V[a].clear();
scanf("%d",&N1);
scanf("%d",&N1);
V[a].resize(N1);
vector<int> &VG=V[a];
REP(b,N1)
{
scanf("%d",&L2);
VG[b]=L2;
}
}
scanf("%d %d",&N1,&M1);
REP(a,L1)
B[a]=INF;
QI K;
K.push(N1);
B[N1]=0;
while(!K.empty())
{
int NN=K.front();
K.pop();
int Odl=B[NN];
vector<int> &VG=V[NN];
REP(a,VG.size())
{
int NrP=VG[a];
if(B[NrP]>Odl+1)
{
B[NrP]=Odl+1;
K.push(NrP);
}
}
}
printf("%d %d %d",N1,M1,B[M1]-1);
if(ZNR!=Zest)
printf("\n");
}
return 0;
}
//---------------------------------------------------------------------------
Users browsing this forum: No registered users and 1 guest