Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Gets the cost of a node, the difference between neighbours from the opposite side and the current side
- *
- * @param int u the node to calculate it's cost
- *
- * @returns int the cost of a node
- *
- */
- int get_cost(int u, vi& neighbours, vi& neighbours_position, vi& sides){
- int side = sides[u];
- int cost = 0;
- for(int i = neighbours_position[u]; i < neighbours_position[u + 1]; ++i){
- if(side == sides[neighbours[i]]) --cost;
- else ++cost;
- }
- return cost;
- }
- /**
- * Gets the cost of swapping two nodes in different sides, the difference between neighbours from the
- * opposite side and the current side
- *
- * @param int u the first node
- * @param int v the second node
- *
- * @returns int the cost of swaping two nodes
- *
- */
- int get_cost(int u, int v, vi& neighbours, vi& neighbours_position, vi& sides){
- return get_cost(u, neighbours, neighbours_position, sides) + get_cost(v, neighbours, neighbours_position, sides) - 2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement