Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct queueEntry
- {
- int v;
- int dist;
- };
- void dadu(int ularTangga[], int N)
- {
- bool *visited = new bool[N];
- for (int i = 0; i < N; i++)
- visited[i] = false;
- queue<queueEntry> q;
- visited[0] = true;
- queueEntry s = {0, 0};
- q.push(s);
- queueEntry qe;
- while (!q.empty())
- {
- qe = q.front();
- int v = qe.v;
- if (v == N-1)
- break;
- q.pop();
- for (int j=v+1; j<=(v+6) && j<N; ++j)
- {
- if (!visited[j])
- {
- queueEntry a;
- a.dist = (qe.dist + 1);
- visited[j] = true;
- if (ularTangga[j] != -1)
- a.v = ularTangga[j];
- else
- a.v = j;
- q.push(a);
- }
- }
- }
- cout << qe.dist << endl ;
- }
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie(NULL);
- int jumKot, num, role, a, b;
- cin >> jumKot >> num;
- int ularTangga[jumKot];
- memset(ularTangga,-1,sizeof(ularTangga[0])*jumKot);
- while(num--){
- cin >> role;
- while(role--){
- cin >> a >> b;
- ularTangga[a] = b;
- }
- dadu(ularTangga, jumKot);
- memset(ularTangga,-1,sizeof(ularTangga[0])*jumKot);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement