Submission #9236

#TimeUsernameProblemLanguageResultExecution timeMemory
9236silasYour life (kriii2_Y)C++98
4 / 4
212 ms7580 KiB
#include <iostream> #include <string.h> #include <queue> #include <vector> #include <utility> #define Nsize 100001 using namespace std; int N, M; // N : 노드의 갯수, 선 갯수 vector<int> arr[Nsize]; int dist[Nsize]; int BFS(int cur) { queue<pair<int,int> > que; que.push(make_pair(1,0)); while (!que.empty()) { int out = que.front().first; int out_dist = que.front().second + 1; que.pop(); for (int i = 0 ; i < arr[out].size(); i++) { if (arr[out][i] == N) { return out_dist; } if (dist[arr[out][i]] == -1) { dist[arr[out][i]] = out_dist; que.push(make_pair(arr[out][i], out_dist)); } } } return -1; } int main() { memset(dist, -1, sizeof(dist)); cin >> N >> M; int temp1, temp2; for (int i = 0 ; i < M; i++) { cin >> temp1 >> temp2; arr[temp1].push_back(temp2); } cout << BFS(1) << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...