forked from khacksOSS/HacktoberFestKarunya2019
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EVEDG.cpp
83 lines (71 loc) · 1.74 KB
/
EVEDG.cpp
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
76
77
78
79
80
81
82
83
//https://www.codechef.com/OCT19B/problems/EVEDG
#include <iostream>
#include <vector>
#define ll long long
using namespace std;
int main()
{
ll t;
cin >> t;
for (ll ii = 0; ii < t; ii++)
{
ll n, m;
cin >> n >> m;
vector<ll> g[n];
for (ll i = 0; i < m; i++)
{
ll x, y;
cin >> x >> y;
g[x-1].push_back(y-1);
g[y-1].push_back(x-1);
}
if(m % 2 == 0)
{
cout << 1 << endl;
for(ll i=0;i<n;i++)
cout << 1 << " ";
}
else
{
ll flag = 0, pos;
for(ll i = 0; i < n; i++)
if(g[i].size() % 2 != 0)
{
pos = i;
flag = 1;
cout << 2 << endl;
break;
}
if(flag)
for(ll i = 0; i < n; i++)
{
if(i == pos)
cout << 2 << " ";
else
cout << 1 << " ";
}
else
{
cout << 3 << endl;
ll pos1, pos2;
for(ll i = 0; i < n; i++)
if(g[i].size() != 0)
{
pos1 = i;
break;
}
pos2 = g[pos1][0];
for(ll i = 0; i < n; i++)
{
if(i == pos1)
cout << 2 << " ";
else if(i == pos2)
cout << 3 << " ";
else
cout << 1 << " ";
}
}
}
cout << endl;
}
}