結果
| 問題 | No.2878 𝕀𝔾ℕ𝕀𝕋𝕀𝕆ℕ |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2026-02-09 10:04:41 |
| 言語 | C++11(廃止可能性あり) (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,198 bytes |
| 記録 | |
| コンパイル時間 | 5,382 ms |
| コンパイル使用メモリ | 182,760 KB |
| 実行使用メモリ | 7,972 KB |
| 最終ジャッジ日時 | 2026-02-09 10:04:52 |
| 合計ジャッジ時間 | 2,874 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 8 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
const int INF = 0x3f3f3f3f;
int n;
int graph[MAXN][MAXN];
int dist[MAXN];
// BFS??????
int bfs(int start, int end) {
// ???????
memset(dist, 0x3f, sizeof(dist));
queue<int> q;
dist[start] = 0;
q.push(start);
while (!q.empty()) {
int u = q.front();
q.pop();
// ????????
if (u == end) {
return dist[u];
}
// ??????
for (int v = 0; v < n; v++) {
// ??u?v????v????
if (graph[u][v] == 1 && dist[v] == INF) {
dist[v] = dist[u] + 1;
q.push(v);
}
}
}
// ????
return -1;
}
int main() {
cin >> n;
// ??????
for (int i = 0; i < n; i++) {
string line;
cin >> line;
for (int j = 0; j < n; j++) {
graph[i][j] = (line[j] == 'Y') ? 1 : 0;
}
}
// ??A?B?????
if (graph[0][1] == 1) {
cout << 0 << endl;
return 0;
}
// BFS???A?B??????????????
int result = bfs(0, 1);
cout << result << endl;
return 0;
}
vjudge1