Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
using namespace std; int n, g[101][101], d[101], s, f; bool used[101]; queue
q; int main() { cin >> n; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { cin >> g[i][j]; } } cin >> s >> f; used[s] = true; d[s] = 0; q.push(s); while (!q.empty()) { int v = q.front(); q.pop(); for (int to = 1; to <= n; ++to) { if (g[v][to] == 1 && !used[to]) { used[to] = true; d[to] = d[v] + 1; q.push(to); } } } if (!used[f]) { cout << -1; } else { cout << d[f]; } return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)