标签:
Jerboas are small desert-living animals, which resemble mice with a long tufted tail and very long hind legs. Jerboas shelter in well-hidden burrows. They create two types of burrow: temporary and permanent. The temporary burrows are plain tubes while the permanent burrows are sealed with a plug of sand to keep heat out and moisture in.
As far as we know, jerboa burrows in the desert are connected with one-way tunnels. What‘s more, for some unknown reasons, it‘s true that start from any burrow, follows the tunnels you can not go back to the starting burrow. Summer means last-minute of offers on good times, so of course jerboas could not stay behind. One day, a little jerboa Alice who lived in a temporary burrow S wants to migrate to a permanent one. There are different routes she can take, but Alice is so odd that she only selects those whose total travel distances is a multiple of K. Among all routes that Alice may select, we are interested in the shortest one. Can you help to find it out? Of course different routes may lead to different destinations.
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iterator>
#include<stack>
using namespace std;
const int INF=1e9+7;
const double eps=1e-7;
const int maxn=1005;
int N,M,start,mod;
bool vis[maxn][maxn];
char road[maxn];
struct node
{
int val,rest,pos;
node(int val=0,int rest=0,int pos=0):val(val),rest(rest),pos(pos){}
bool operator < (const node& t) const{ return val>t.val; }
};
priority_queue<node> que;
struct edge
{
int u,v,c;
edge(int u=0,int v=0,int c=0):u(u),v(v),c(c){}
};
vector<edge> G[maxn];
void init()
{
while(!que.empty()) que.pop();
for(int i=0;i<maxn;i++) G[i].clear();
memset(vis,false,sizeof(vis));
}
void solve()
{
int ansl=INF,ansp=-1;
que.push(node(0,0,start));
vis[0][start]=true;
while(!que.empty())
{
node t=que.top(); que.pop();
int val=t.val,rest=t.rest,pos=t.pos;
if(val>ansl) break; //路径长度大了
if(rest==0&&road[pos