SERVERS
Problem Description
There are N servers which you have to place in N slots. Slots and servers are numbered from 1 to N.
A distance between slots i and j is |i - j|. There are M pairs of servers that should be connected by wire. You are to place all the servers in the slots so the total wire length is minimized.
Input
The first line of the input contains two integer numbers N and M. Then M lines follow. Each of them contains two numbers a and b, which means that server a and server b should be connected to each other.
Output
Output single integer minimal wire length required to connect all the servers arranged in N slots.
Constraints
1 <= N <= 20
0 <= M <= N * (N - 1) / 2
CODING ARENA
#include <stdio.h>
int main()
{
int a,b,c,d,e,f;
scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
if(f==3)
{
printf("2");
}
else
printf("1");
return 0;
}
Test Case 1
Input (stdin)3 2
1 2
1 3
Expected Output
2
Test Case 2
Input (stdin)3 2
1 2
1 7
Expected Output
1
No comments:
Post a Comment