From ab6136dcf9439e687e20ec3c61de5b3d8bc7fc7e Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Sat, 12 Oct 2024 14:42:48 +0800 Subject: [PATCH 1/2] update --- src/P1330/P1330.cpp | 65 +------------------------------------ src/P1330/P1330_failed.cpp | 66 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 64 deletions(-) create mode 100644 src/P1330/P1330_failed.cpp diff --git a/src/P1330/P1330.cpp b/src/P1330/P1330.cpp index 9cf8cf1..294989d 100644 --- a/src/P1330/P1330.cpp +++ b/src/P1330/P1330.cpp @@ -1,66 +1,3 @@ -#include -#include -#include -#include -#include -#include -#include - -using ll = long long; -static const ll max_n = 1e4+5; -static auto &is = std::cin; -static auto &os = std::cout; - -static ll n,m,u,v; -std::vector map[max_n]; -std::bitset vis; -std::array colors; -struct Status{ - ll now; - int color; -}; -std::queue q; -ll color_sum[3]; - -void bfs(){ - for(ll i{1};i<=n;i++){ - if(vis[i])continue; - colors[i]=1; - color_sum[colors[i]]++; - vis[i]=true; - q.push({i,colors[i]}); - while(!q.empty()){ - const auto front = q.front(); - q.pop(); - - for(const auto i:map[front.now]){ - const Status next_status{i,((front.color&1)+1)}; - if(vis[next_status.now]){ - if(next_status.color!=colors[next_status.color]){ - os<<"Impossible\n"; - _exit(0); - } - continue; - } - colors[next_status.now]=next_status.color; - color_sum[colors[next_status.now]]++; - vis[next_status.now]=true; - q.push(next_status); - } - } - } - return; -} int main(){ - is>>n>>m; - - for(ll i{0};i>u>>v; - map[u].push_back(v); - map[v].push_back(u); - } - - bfs(); - - os< +#include +#include +#include +#include +#include +#include + +using ll = long long; +static const ll max_n = 1e4+5; +static auto &is = std::cin; +static auto &os = std::cout; + +static ll n,m,u,v; +std::vector map[max_n]; +std::bitset vis; +std::array colors; +struct Status{ + ll now; + int color; +}; +std::queue q; +ll color_sum[3]; + +void bfs(){ + for(ll i{1};i<=n;i++){ + if(vis[i])continue; + colors[i]=1; + color_sum[colors[i]]++; + vis[i]=true; + q.push({i,colors[i]}); + while(!q.empty()){ + const auto front = q.front(); + q.pop(); + + for(const auto i:map[front.now]){ + const Status next_status{i,((front.color&1)+1)}; + if(vis[next_status.now]){ + if(next_status.color!=colors[next_status.color]){ + os<<"Impossible\n"; + _exit(0); + } + continue; + } + colors[next_status.now]=next_status.color; + color_sum[colors[next_status.now]]++; + vis[next_status.now]=true; + q.push(next_status); + } + } + } + return; +} +int main(){ + is>>n>>m; + + for(ll i{0};i>u>>v; + map[u].push_back(v); + map[v].push_back(u); + } + + bfs(); + + os< Date: Sat, 12 Oct 2024 15:00:59 +0800 Subject: [PATCH 2/2] update --- src/P1330/P1330.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/src/P1330/P1330.cpp b/src/P1330/P1330.cpp index 294989d..a27d4bf 100644 --- a/src/P1330/P1330.cpp +++ b/src/P1330/P1330.cpp @@ -1,3 +1,65 @@ +#include +#include +#include +#include + +using ll = long long; +using std::endl; +static auto &is = std::cin; +static auto &os = std::cout; + +static const ll max_n = 1e4+5; + +static ll n, m, a, b; +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]; +void set_color(const ll n,const int color)noexcept{ + colors[n]=color; + color_sum[color]++; +} + +void flush_exit()noexcept{ + os<>n>>m; + for(ll i{0};i>a>>b; + next[a].push_back(b); + next[b].push_back(a); + } + + bfs(); + os<