Ultrafast lattice dynamics and microscopic energy flow in ferromagnetic metals and in an anisotropic layered semiconductor