G. Graph Orientation
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Examples
Input
6 5
5 4 8 4 1 2
1 5
3 5
5 6
2 6
6 4
Output
3
5 1
5 3
5 6
6 2
6 4
Input
4 4
6 9 8 4
1 2
2 3
3 4
4 1
Output
13
2 1
2 3
4 3
4 1