#include <bits/stdc++.h>
using namespace std;
struct Fastio
{
template <typename T>
inline Fastio operator>>(T &x)
{
x = 0;
char c = getchar();
while (c < ‘0‘ || c > ‘9‘)
c = getchar();
while (c >= ‘0‘ && c <= ‘9‘)
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return *this;
}
inline Fastio &operator<<(const char *str)
{
int cur = 0;
while (str[cur])putchar(str[cur++]);
return *this;
}
template <typename T>
inline Fastio &operator<<(T x)
{
if (x == 0)
{
putchar(‘0‘);
return *this;
}
if (x < 0) putchar(‘-‘), x = -x;
static int sta[45];
int top = 0;
while (x) sta[++top] = x % 10, x /= 10;
while (top) putchar(sta[top] + ‘0‘), --top;
return *this;
}
} io;
int n, m, rt, ans, cnt_node, cntn;
int cnt;
array<int, 2000005> head;
struct abc
{
int from, to, nxt, idg;
};
array<abc, 2000005> dd;
array<int, 2000005> dfn, low;
stack<int> s, sp;
array<int, 2000005> id;
array<int, 2000005> Min;
inline void add(int u, int v, int idp)
{
dd[++cnt].to = v;
dd[cnt].from = u;
dd[cnt].idg = idp;
dd[cnt].nxt = head[u];
head[u] = cnt;
}
#define js(x) x % 2 ? x + 1 : x - 1
void tarjan(int u, int fa)
{
dfn[u] = low[u] = ++cnt_node;
for (int i = head[u]; i; i = dd[i].nxt)
{
int v = dd[i].to;
if(id[dd[i].idg]) continue;
if (!dfn[v])
{
s.push(dd[i].idg);
tarjan(v, u);
low[u] = min(low[u], low[v]);
if (low[v] >= dfn[u])
{
cntn++;
int ret = INT_MAX;
int tp;
while(1)
{
tp = s.top();
s.pop();
id[tp] = cntn;
ret = min(ret, tp);
if(tp == dd[i].idg) break;
}
Min[cntn] = ret;
// io << "\n";
}
}
else if(v != fa)
{
s.push(dd[i].idg);
low[u] = min(low[u], dfn[v]);
}
}
}
signed main()
{
io >> n >> m;
for(int i = 1; i <= m; ++i)
{
int u, v;
io >> u >> v;
add(u, v, i);
add(v, u, i);
}
Min.fill(1);
for(int i = 1; i <= n; ++i)
if(!dfn[i]) tarjan(i, 0);
io << cntn << "\n";
for(int i = 1; i <= m; ++i) io << Min[id[i]] << " ";
return 0;
}
云剪贴板