Memo
Memory : 2016 KB
Time : 0 ms
Code
#include <bits/stdc++.h>
using namespace std;
int bam[107];
queue<pair<int, int> > q;
int bfs(int pos, int depth)
{
int max = 6;
if (pos >= 100)
return depth;
for(int i = 6;i>0;i--){
if(bam[pos + i] == -1)
continue ;
if(bam[pos + i])
q.push(make_pair(bam[pos + i], depth + 1));
else
q.push(make_pair(pos + i, depth + 1));
bam[pos + i] = -1;
}
pair<int, int> p = q.front();
q.pop();
return bfs(p.first, p.second);
}
int main()
{
int n,m;
scanf("%d %d",&n,&m);
memset(bam, 0, sizeof(bam));
for(int i=0;i<n+m;i++)
{
int x,y;
scanf("%d %d",&x,&y);
bam[x] = y;
}
printf("%d",bfs(1,0));
}
C++
복사