Tap here to switch tabs
Problem
Submissions

Problem: Flower Planting With No Adjacent

Try to solve the Flower Planting With No Adjacent problem.

Statement

You have n gardens labeled from 11 to n, and an array paths where paths[i] =[xi,yi]= [x_i, y_i] represents a bidirectional path connecting garden xix_i and garden yiy_i.

You must plant one of 44 flower types in each garden such that no two gardens connected by a path have the same flower type.

Return an array answer of length n, where answer[i] is the flower type planted in garden i+1i + 1. The flower types are represented by the integers 11, 22, 33, and 44. It is guaranteed that a valid answer exists. If there are multiple valid answers, return any of them.

Constraints:

  • 1≤1 \leq n ≤104\leq 10^4

  • 0≤0 \leq paths.length ≤2×104\leq 2 \times 10^4

  • paths[i].length =2= 2

  • 1≤xi,yi≤1 \leq x_i, y_i \leq n

  • xi≠yix_i \neq y_i

  • Every garden has at most 33 paths connected to it.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Flower Planting With No Adjacent

Try to solve the Flower Planting With No Adjacent problem.

Statement

You have n gardens labeled from 11 to n, and an array paths where paths[i] =[xi,yi]= [x_i, y_i] represents a bidirectional path connecting garden xix_i and garden yiy_i.

You must plant one of 44 flower types in each garden such that no two gardens connected by a path have the same flower type.

Return an array answer of length n, where answer[i] is the flower type planted in garden i+1i + 1. The flower types are represented by the integers 11, 22, 33, and 44. It is guaranteed that a valid answer exists. If there are multiple valid answers, return any of them.

Constraints:

  • 1≤1 \leq n ≤104\leq 10^4

  • 0≤0 \leq paths.length ≤2×104\leq 2 \times 10^4

  • paths[i].length =2= 2

  • 1≤xi,yi≤1 \leq x_i, y_i \leq n

  • xi≠yix_i \neq y_i

  • Every garden has at most 33 paths connected to it.