diff --git a/README.md b/README.md index 93295e0..8ed2382 100755 --- a/README.md +++ b/README.md @@ -23,4 +23,17 @@ struct Status{ }; std::priority_queue q; +``` + +### [P1330](https://www.luogu.com.cn/problem/P1330) +#### BFS时注意初始化一开始的去重数组 +```cpp +void bfs(){ + for(ll i{1};i<=n;i++){ + color_sum[1]=color_sum[2]=0; + if(vis[i])continue; + q.push(i); + set_color(i, 1); + vis[i]=true; // 注意初始化错误 + while(!q.empty()){ ``` \ No newline at end of file diff --git a/src/P1330/P1330.cpp b/src/P1330/P1330.cpp index 9325224..34bc419 100644 --- a/src/P1330/P1330.cpp +++ b/src/P1330/P1330.cpp @@ -1,14 +1,7 @@ -//#define NDEBUG #include #include #include #include -#define NV(v)#v<<" : "<<(v) -#ifdef NDEBUG -#define DEBUG(code) -#else -#define DEBUG(code){code} -#endif using ll = long long; using std::endl; @@ -22,22 +15,24 @@ static std::vector next[max_n]; static bool vis[max_n]; static std::queue q; static int colors[max_n]; -static ll color_sum[3]; +static ll color_sum[3], ans; void set_color(const ll n,const int color)noexcept{ colors[n]=color; color_sum[color]++; } void flush_exit()noexcept{ - os<