这是一道面试题。
N 个节点,每个节点由几个字段和方法组成。这些是:
// Every node has an ID. All of these IDs are sequential, and begin with 0.
// i.e. all ids are uniquely in the range of 0 t N-1
int id;
int val; // Every node has a value
int max; // max = N. Every node knows how many nodes are in the system.
void send(int idTo, int payload)
int recv(int idFrom)
编写一段同时在每个节点上运行的代码,这样当它完成运行时系统中的每个节点都知道系统中所有节点的值的总和。