Skip to content

Conversation

wheson
Copy link
Contributor

@wheson wheson commented Mar 31, 2018

Dinicクラスを実装しました.

@wheson
Copy link
Contributor Author

wheson commented Mar 31, 2018

写経をしやすいようにするライブラリなのに(int)などのキャストをstatic_cast()にしないといけないのはどうなのかなと思いました.

@odanado
Copy link
Member

odanado commented Apr 1, 2018

static_cast ってcpplintに怒られているんですか

@wheson
Copy link
Contributor Author

wheson commented Apr 1, 2018

./lib/Graph/dinic.cpp:28: Using C-style cast. Use static_cast(...) instead [readability/casting] [4]
./lib/Graph/dinic.cpp:29: Using C-style cast. Use static_cast(...) instead [readability/casting] [4]
./lib/Graph/dinic.cpp:52: Using C-style cast. Use static_cast(...) instead [readability/casting] [4]
こんな感じで指定されました

@odanado
Copy link
Member

odanado commented Apr 2, 2018

なるほど
手元の環境だとそもそもキャストしないコードを書くと0エラーになるんですが、そちらの環境ではどうでしょうか?

vector<T> minCost;
vector<int> iter;
vector<vector<Edge<T>>> graph;
const T INF = numeric_limits<T>::max();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INFに最大値をそのまま使うのは、1以上の数字を足した時にオーバーフローするので良くないとされています(蟻本の最初の方のINFが初登場するらへんに書いてたはず)
なので、最大値を10割った値ぐらいに設定する必要があります

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど.それは意識していませんでした.10で割った数に変えます

@wheson
Copy link
Contributor Author

wheson commented Apr 3, 2018

0エラーというのはstatic_castを外した状態で起きているのですか?
元々はC言語方式のキャスト(int)を使っていたのですが,それでは問題なく動いていました.

@odanado
Copy link
Member

odanado commented Apr 3, 2018

(int)static_cast<int>() も使わないということです

template <typename T>
T Dinic<T>::Dfs(int idx, const int t, T flow) {
if (idx == t) return flow;
for (int &i = iter[idx]; i < static_cast<int>(graph[idx].size()); ++i) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここの static_cast はなくてもエラーにならないと思います

Copy link
Contributor Author

@wheson wheson Apr 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確かに大丈夫でした.修正します

Copy link
Member

@odanado odanado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

良さそうなのでマージお願いします
(僕がマージするより本人にしてもらうほうが良いと気付いた)

@wheson wheson merged commit 6df7f7c into master Apr 29, 2018
@wheson wheson deleted the add-dinic branch June 11, 2018 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants