Submission #4308961
Source Code Expand
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> Pair; #define MM 1000000000 #define MOD MM+7 #define MAX 10000 #define MAP 51 #define GRAPH 50 int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, -1, 0, 1}; int n,m; int R,C,sx,sy,gx,gy; char c[MAP][MAP]; int dist[MAP][MAP]; Pair s, g; int dfs(){ queue<Pair> que; for(int i = 0; i < R; i++){ for(int j = 0; j < C; j++){ dist[i][j] = MAX; } } que.push(Pair(s.first-1, s.second-1)); d[s.first-1][s.second-1] = 0;; while(que.size()){ Pair p = que.front(); que.pop(); for(int i = 0; i < 4; i++){ int nx = p.first + dx[i]; int ny = p.second + dy[i]; if(c[nx][ny] == '.' && d[nx][ny] == MAX){ que.push(Pair(nx,ny)); d[nx][ny] = d[p.first][p.second] + 1; } } } return d[g.first-1][g.second-1]; } int main(){ scanf("%d %d", &R, &C); scanf("%d %d", &s.first, &s.second); scanf("%d %d", &g.first, &g.second); for(int i = 0; i < R; i++){ for(int j = 0; j < C; j++){ cin >> c[i][j]; } } int ans = dfs(); cout << ans << endl; }
Submission Info
Submission Time | |
---|---|
Task | C - 幅優先探索 |
User | Kant |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1278 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘int dfs()’: ./Main.cpp:25:5: error: ‘d’ was not declared in this scope d[s.first-1][s.second-1] = 0;; ^ ./Main.cpp: In function ‘int main()’: ./Main.cpp:41:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d %d", &R, &C); ^ ./Main.cpp:42:40: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d %d", &s.first, &s.second); ^ ./Main.cpp:43:40: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d %d", &g.first, &g.second); ^