data-structures · intermediate · ~15 min
Check a coloring constraint.
int is_valid_coloring(const int *adj,int n,const int *color);
Given a color per vertex, return 1 if it is a proper coloring (no edge joins two equal colors), else 0.
adj n×n symmetric; color length n.
1 if proper, else 0.
Colors may be any ints.
#include <stddef.h>
/* Given a color per node, return 1 if it is a proper coloring (no edge joins two same-colored nodes), else 0. */
int is_valid_coloring(const int *adj,int n,const int *color){ (void)adj;(void)n;(void)color; return 1; }
Checking only one direction of the matrix (harmless here, but scan all edges).
No edges → always valid.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.