/*
* File: Timus 1040. Airline company
* Author: xiaotian @ hnu
* Created on 2010年10月2日, 上午9:34
* 题解:一次找极长路(即两边不能再加边),将他们依次编号,然后删掉这些边。直至图中没有边为止。输出解即可。
* 不会出现没有解的情况。
*/
1 #include <iostream>
2 #include<string.h>
3 #include<iostream>
4 #define N 55
5 using namespace std;
6 int n, m;
7 int g[N][N];
8 int link[N][N];
9 int num[N*N];
10 int now;
11 bool vis[N];
12 bool p[N*N];
13
14 void dfs(int x) {
15 for (int i = 1; i <= g[x][0]; ++i)
16 if (!p[link[x][i]]) {
17 p[link[x][i]] = true;
18 num[link[x][i]] = ++now;
19 if (!vis[g[x][i]]) {
20 vis[g[x][i]] = true;
21 dfs(g[x][i]);
22 }
23 }
24 }
25
26 int main() {
27 while (scanf("%d %d", &n, &m) != EOF) {
28 memset(vis,0,sizeof(vis));
29 memset(p,0,sizeof(p));
30 now=0;
31 for (int i = 0; i <= n; i++) g[i][0] = link[i][0] = 0;
32 for (int i = 1; i <= m; ++i) {
33 int a, b;
34 scanf("%d %d", &a, &b);
35 g[a][++g[a][0]] = b;
36 g[b][++g[b][0]] = a;
37 link[a][++link[a][0]] = i;
38 link[b][++link[b][0]] = i;
39 }
40 vis[1] = true;
41 dfs(1);
42 puts("YES");
43 for (int i = 1; i <= m; ++i) printf("%d ", num[i]);
44 }
45 }