0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【C言語】隣接行列でサイクルを作成する/しない

Posted at

概要

隣接行列におけるサイクルを作成する、しないの条件をなかなか実装できず、有識者に教えていただいたのでメモとして記事にしようと思います。

コード

前提条件として、ひとつの頂点からは辺が1本の一方向にのみ生成されるという場合を考えています

qiita.rb
// j -> i へのパスが存在するか
cur_node = j;
while (true) {
  if (cur_node == i) {
    // パスが存在する
    // do something
    break;
  }
  bool end = true; // while 終了フラグ
  for (int to = 0; to < n; to++) {
    // 辺が存在したら進む
    if (locked[cur_node][to]) {
      cur_node = to;
      end = false;
      break;
    }
  }
  if (end) break;
}
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?