Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
using namespace std; typedef long long ll; #define pb push_back #define mp make_pair #define f first #define s second int main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); int n, m; cin >> n >> m; vector
graph[n+5]; for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; graph[a-1].pb(b-1); graph[b-1].pb(a-1); } vector
visited(n, false); vector
col(n, -1); for(int i = 0; i < n; i++){ if(col[i] != -1) continue; visited[i] = true; col[i] = 1; queue
q; q.push(i); while(!q.empty()){ int c = q.front(); q.pop(); for(int j = 0; j < (int) graph[c].size(); j++){ int z = graph[c][j]; if(col[c] != -1 and col[z] != -1 and col[c] == col[z]) { cout << "IMPOSSIBLE" << endl; return 0; } if(visited[z]) continue; visited[z] = true; if(col[z] == -1){ if(col[c] == 1) col[z] = 2; if(col[c] == 2) col[z] = 1; q.push(z); }else { if(col[c] == col[z]){ cout << "IMPOSSIBLE" << endl; return 0; } } } } } for(int i = 0; i < n; i++){ cout << col[i] << " "; } return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)