Last active
February 26, 2016 01:13
-
-
Save lktslionel/767c05100c4061136028 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Auto-generated code below aims at helping you parse | |
* the standard input according to the problem statement. | |
**/ | |
var inputs = readline().split(' '); | |
var N = parseInt(inputs[0]); // the total number of nodes in the level, including the gateways | |
var L = parseInt(inputs[1]); // the number of links | |
var E = parseInt(inputs[2]); // the number of exit | |
var links = [] | |
var gates = [] | |
var brokenLinks = [] | |
for (var i = 0; i < L; i++) { | |
links[i] = [0,0]; | |
} | |
for (var i = 0; i < L; i++) { | |
var inputs = readline().split(' '); | |
var N1 = parseInt(inputs[0]); // N1 and N2 defines a link between these nodes | |
var N2 = parseInt(inputs[1]); | |
links[N1][N2] = 1; | |
} | |
for (var i = 0; i < E; i++) { | |
var EI = parseInt(readline()); // the index of a gateway node | |
gates.push(EI); | |
} | |
// game loop | |
while (true) { | |
var SI = parseInt(readline()); // The index of the node on which the Skynet agent is positioned this turn | |
// Write an action using print() | |
// To debug: printErr('Debug messages...'); | |
gates.forEach((g) => { | |
if (links[SI][g] == 1 || links[g][SI] == 1) { | |
print( ((SI < g) ? [SI, g] : [g, SI]).join(" ")); | |
} | |
}); | |
//print('0 1'); // Example: 0 1 are the indices of the nodes you wish to sever the link between | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Auto-generated code below aims at helping you parse | |
* the standard input according to the problem statement. | |
**/ | |
/** | |
* Check if there are any successor node (n), from the given list, | |
* that has a relation with one of gateway nodes. | |
* | |
* It prints indices of the nodes you wish to delete in order to isolate block the agent. | |
* | |
* @param {Array[int]} list of node indices | |
*/ | |
let checkSuccessors = (successors) => { | |
if (!successors.length) { | |
return | |
} else { | |
let n = successors.shift(); | |
gates.forEach((g) => { | |
if (links[n][g] == 1 || links[g][n] == 1) { | |
print( ((n < g) ? [n, g] : [g, n]).join(" ")); | |
} | |
}); | |
// Also start the check recursively on successors of the node and the rest of successors. | |
checkSuccessors(getSuccessorsOf(n)); | |
checkSuccessors(successors); | |
} | |
} | |
/** | |
* Return the list of successors of a given node indice. | |
* | |
* @param {int} node indice. | |
* @return {Array[int]} list of successor's indices. | |
*/ | |
let getSuccessorsOf = (n) => { | |
var s = $successors[n]; | |
printErr("$s["+n+"]="+s); | |
return s; | |
} | |
var inputs = readline().split(' '); | |
var N = parseInt(inputs[0]); // the total number of nodes in the level, including the gateways | |
var L = parseInt(inputs[1]); // the number of links | |
var E = parseInt(inputs[2]); // the number of exit | |
var links = []; // The matrix that keep info about relations between nodes. | |
var gates = []; // The list of gateway indices. | |
var brokenLinks = []; // The list of link that need to be brocken to isolate the agent. | |
var $successors = []; // The associative array that keeps successors of every nodes. | |
for (var i = 0; i < L; i++) { | |
// Initializing links (zero filled matrix) and successors | |
links[i] = [0,0]; | |
$successors[i] = []; | |
} | |
for (var i = 0; i < L; i++) { | |
var inputs = readline().split(' '); | |
var N1 = parseInt(inputs[0]); // N1 and N2 defines a link between these nodes | |
var N2 = parseInt(inputs[1]); | |
// Assign 1 to the element in the matrix at position (i,i) = (N1,N2) | |
links[N1][N2] = 1; | |
// printErr("(i="+i+", N1="+N1+", N2="+N2+")"); | |
// Store sucessors of every nodes for later uses. | |
$successors[N1].push(N2); | |
//printErr("$s["+N1+"]="+$successors[N1]); | |
} | |
for (var i = 0; i < E; i++) { | |
var EI = parseInt(readline()); // the indices of a gateway node | |
gates.push(EI); | |
} | |
// game loop | |
while (true) { | |
var SI = parseInt(readline()); // The indices of the node on which the Skynet agent is positioned this turn | |
printErr(SI); | |
// Start checking the indices of the agent and its successors. | |
checkSuccessors([SI]); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment