회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
살려주세요 3일째 안됩니다 ㅠㅠㅠ
14940번 - 쉬운 최단거리
dhlee9255
2년 전
0
아무리 해도 그래프를 안돌고 있는것 같은데
뭐가 문제인지 모르겠어요
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <cmath> #include <queue> #include <numeric> #include <set> using namespace std; //포기 int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; int ans[1001][1001]; int board[1001][1001]={0,}; pair<int,int>goal; //도착지점 int n,m; void bfs(){ queue<pair<int,int>>q; q.push(goal); ans[goal.first][goal.second]=0; while(!q.empty()){ int fx=q.front().first; int fy=q.front().second; q.pop(); for(int i=0; i<4; i++){ int nx=fx+dx[i]; int ny=fx+dy[i]; if(nx<0||ny<0||nx>=n||ny>=m){ continue; } if(ans[nx][ny]!=-1||board[nx][ny]==0){ continue; } q.push({nx,ny}); ans[nx][ny]=ans[fx][fy]+1; } } } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); for(int i=0; i<1001; i++){ for(int k=0; k<1001; k++){ //ans 초기화 ans[i][k]=-1; } } cin>>n>>m; for(int i=1; i<=n; i++){ for(int k=1; k<=m; k++){ cin>>board[i][k]; if(board[i][k]==2){ goal=make_pair(k,i); } } } bfs(); for(int i=1; i<=n; i++){ for(int k=1; k<=m; k++){ if(board[i][k]==0){ cout<<0<<" "; } else{ cout<<ans[i][k]<<" "; } } cout<<"\n"; } return 0; }
댓글을 작성하려면
로그인
해야 합니다.
dhlee9255 2년 전
아무리 해도 그래프를 안돌고 있는것 같은데
뭐가 문제인지 모르겠어요