|
| 1 | +<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> |
| 2 | +<!--+----------------------------------------------------------------------+--> |
| 3 | +<!--|@author Openset <openset.wang@gmail.com> |--> |
| 4 | +<!--|@link https://github.com/openset |--> |
| 5 | +<!--|@home https://github.com/openset/leetcode |--> |
| 6 | +<!--+----------------------------------------------------------------------+--> |
| 7 | + |
| 8 | +[< Previous](https://github.com/openset/leetcode/tree/master/problems/robot-bounded-in-circle "Robot Bounded In Circle") |
| 9 | + |
| 10 | +[Next >](https://github.com/openset/leetcode/tree/master/problems/partition-array-for-maximum-sum "Partition Array for Maximum Sum") |
| 11 | + |
| 12 | +## 1042. Flower Planting With No Adjacent (Easy) |
| 13 | + |
| 14 | +<p>You have <code>N</code> gardens, labelled <code>1</code> to <code>N</code>. In each garden, you want to plant one of 4 types of flowers.</p> |
| 15 | + |
| 16 | +<p><code>paths[i] = [x, y]</code> describes the existence of a bidirectional path from garden <code>x</code> to garden <code>y</code>.</p> |
| 17 | + |
| 18 | +<p>Also, there is no garden that has more than 3 paths coming into or leaving it.</p> |
| 19 | + |
| 20 | +<p>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.</p> |
| 21 | + |
| 22 | +<p>Return <strong>any</strong> such a choice as an array <code>answer</code>, where <code>answer[i]</code> is the type of flower planted in the <code>(i+1)</code>-th garden. The flower types are denoted <font face="monospace">1</font>, <font face="monospace">2</font>, <font face="monospace">3</font>, or <font face="monospace">4</font>. It is guaranteed an answer exists.</p> |
| 23 | + |
| 24 | +<p> </p> |
| 25 | + |
| 26 | +<div> |
| 27 | +<p><strong>Example 1:</strong></p> |
| 28 | + |
| 29 | +<pre> |
| 30 | +<strong>Input: </strong>N = <span id="example-input-1-1">3</span>, paths = <span id="example-input-1-2">[[1,2],[2,3],[3,1]]</span> |
| 31 | +<strong>Output: </strong><span id="example-output-1">[1,2,3]</span> |
| 32 | +</pre> |
| 33 | + |
| 34 | +<div> |
| 35 | +<p><strong>Example 2:</strong></p> |
| 36 | + |
| 37 | +<pre> |
| 38 | +<strong>Input: </strong>N = <span id="example-input-2-1">4</span>, paths = <span id="example-input-2-2">[[1,2],[3,4]]</span> |
| 39 | +<strong>Output: </strong><span id="example-output-2">[1,2,1,2]</span> |
| 40 | +</pre> |
| 41 | + |
| 42 | +<div> |
| 43 | +<p><strong>Example 3:</strong></p> |
| 44 | + |
| 45 | +<pre> |
| 46 | +<strong>Input: </strong>N = <span id="example-input-3-1">4</span>, paths = <span id="example-input-3-2">[[1,2],[2,3],[3,4],[4,1],[1,3],[2,4]]</span> |
| 47 | +<strong>Output: </strong><span id="example-output-3">[1,2,3,4]</span> |
| 48 | +</pre> |
| 49 | + |
| 50 | +<p> </p> |
| 51 | + |
| 52 | +<p><strong><span>Note:</span></strong></p> |
| 53 | + |
| 54 | +<ul> |
| 55 | + <li><code><span>1 <= N <= 10000</span></code></li> |
| 56 | + <li><code><span>0 <= paths.size <= 20000</span></code></li> |
| 57 | + <li>No garden has 4 or more paths coming into or leaving it.</li> |
| 58 | + <li>It is guaranteed an answer exists.</li> |
| 59 | +</ul> |
| 60 | +</div> |
| 61 | +</div> |
| 62 | +</div> |
0 commit comments