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<