You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You have n gardens, labeled from 1 to n, and an array paths where paths[i] = [xi, yi] describes a bidirectional path between garden xi to garden yi. In each garden, you want to plant one of 4 types of flowers.
5
+
6
+
All gardens have at most 3 paths coming into or leaving it.
7
+
8
+
Your task is to choose a flower type for each garden such that, for any two gardens connected by a path, they have different types of flowers.
9
+
10
+
Return any such a choice as an array answer, where answer[i] is the type of flower planted in the (i+1)th garden. The flower types are denoted 1, 2, 3, or 4. It is guaranteed an answer exists.
11
+
12
+
Example 1:
13
+
14
+
Input: n = 3, paths = [[1,2],[2,3],[3,1]]
15
+
Output: [1,2,3]
16
+
Explanation:
17
+
Gardens 1 and 2 have different types.
18
+
Gardens 2 and 3 have different types.
19
+
Gardens 3 and 1 have different types.
20
+
Hence, [1,2,3] is a valid answer. Other valid answers include [1,2,4], [1,4,2], and [3,2,1].
21
+
22
+
Example 2:
23
+
24
+
Input: n = 4, paths = [[1,2],[3,4]]
25
+
Output: [1,2,1,2]
26
+
27
+
Example 3:
28
+
29
+
Input: n = 4, paths = [[1,2],[2,3],[3,4],[4,1],[1,3],[2,4]]
30
+
Output: [1,2,3,4]
31
+
32
+
Constraints:
33
+
34
+
1 <= n <= 104
35
+
0 <= paths.length <= 2 * 104
36
+
paths[i].length == 2
37
+
1 <= xi, yi <= n
38
+
xi != yi
39
+
Every garden has at most 3 paths coming into or leaving it.
0 commit comments