Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main(int argc, char const *argv[])
- {
- int n, s, d;
- scanf("%d %d %d", &n, &s, &d);
- int a[n+1][n+1];
- bool vis[n+1], ok=0;
- for (int i=1; i<=n; i++)
- for (int j=1; j<=n; j++)
- scanf("%d", &a[i][j]);
- for (int i=0; i<=n; i++)
- vis[i]=0;
- queue<int> q;
- q.push(s);
- vis[s]=1;
- int cows=0;
- while (!q.empty()) {
- int u=q.front();
- q.pop();
- if (u==d) {
- ok=1;
- goto END;
- }
- for (int i=1; i<=n; i++) {
- if (a[u][i]==1 and !vis[i]) {
- vis[i]=1;
- q.push(i);
- cows++;
- }
- }
- }
- END:
- if (ok)
- printf("Gotcha Mamu! Used %d cows\n", cows);
- else
- printf("Wasted %d cows for mamar halim\n", cows);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement