1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| const int maxn = 10000 + 10;
class Edge { public: int from, to; Edge(int f = 0, int t = 0) : from(f), to(t) {} };
vector<Edge> edges; vector<int> G[maxn]; int n, m, k;
int color[maxn], vis[maxn];
void init() { Set(color, 0); Set(vis, 0); _for(i, 0, maxn) G[i].clear(); edges.clear(); k = 0; }
void initVis() { Set(vis, 0); }
void addEdge(int from, int to) { edges.push_back(Edge(from, to)); int m = edges.size(); G[from].push_back(m - 1); }
void dfs(int u) { initVis(); _for(i, 0, G[u].size()) { Edge cur = edges[G[u][i]]; if(color[cur.to]) vis[color[cur.to]] = 1; }
_rep(i, 1, k) { if(!vis[i]) { color[u] = i; break; } }
_for(i, 0, G[u].size()) { Edge cur = edges[G[u][i]]; if(!color[cur.to]) dfs(cur.to); } }
int main() { freopen("input.txt", "r", stdin); int kase = 0;
while (scanf("%d%d", &n, &m) != EOF) { init(); if(++kase > 1) printf("\n");
int u, v; _for(i, 0, m) { scanf("%d%d", &u, &v); addEdge(u - 1, v - 1); addEdge(v - 1, u - 1); } _for(i, 0, n) k = max(k, (int)G[i].size());
if(k % 2 == 0) k++; cout << k << endl;
dfs(0); _for(i, 0, n) cout << color[i] << endl; } }
|