2012-11-07 16:00:00 UTC

# toc toc

Status: Passed
Results: 77452 (cyc: 5, node: 498)
CPU Time: 0.823
Score: 77467.9
Submitted at: 2012-11-01 05:24:11 UTC
Scored at: 2012-11-01 17:16:00 UTC

Current Rank: 1674th (Highest: 15th )

Code
```function xyOut = solver(a, xyIn, wts)

[x, y] = make_layout(a);
xyIn = remove_overlapping_nodes(round(vertcat(x, y)*30)');

xyOut = xyIn;

end

function G = remove_overlapping_nodes(e)

[C, ia, ic] = unique(e,'rows');
D = setdiff(1:size(e, 1), ia);
if numel(D)>0
for i = 1:size(D)
e(D(i),:) =   e(D(i),:) + [0 1];
end
e = remove_overlapping_nodes(e);
end

G=e;
end

%  [x, y] = make_layout(adj)  Creates a layout from an adjacency matrix
%
% OUTPUT: x, y - Positions of nodes
%
% WARNING: Uses some very simple heuristics, any algorithm would do better

if ~isempty(tps),       % is directed ?
level = zeros(1,N);
for i=tps,
if ~isempty(idx),
l = max(level(idx));
level(i)=l+1;
end;
end;
else
end;
level;
y = (level+1)./(max(level)+2);
y = 1 - y;
x = zeros(size(y));
for i = 0:max(level),
idx = find(level==i);
offset = (rem(i,2)-0.5)/10;
x(idx) = (1:length(idx))./(length(idx)+1)+offset;
end;
end

% [depth] = poset(adj, root)   Identify a partial ordering among the nodes of a graph
% OUTPUT:  depth - Depth of the node
% Note     : All Nodes must be connected
depth = zeros(N,1);
depth(root) = 1;
queue = root;
while 1,
if isempty(queue),
if all(depth),
break;
else
root = find(depth==0);
root = root(1);
depth(root) = 1;
queue = root;
end
end
r = queue(1); queue(1) = [];
idx2 = find(~depth(idx));
idx = idx(idx2);
queue = [queue idx];
depth(idx) = depth(r) + 1;
end;
end

% [seq] = toposort(adj)  A Topological ordering of nodes in a directed graph
% OUTPUT: seq  -  a topological ordered sequence of nodes
%                 or an empty matrix if graph contains cycles
seq = [];
for i = 1:N,
idx = find(indeg==0);    % Find nodes with indegree 0
if isempty(idx),   % If can't find than graph contains a cycle
seq = [];
break;
end;
[dummy idx2] = max(outdeg(idx)); % Remove the node with the max number of connections
indx = idx(idx2);
seq = [seq, indx];
indeg(indx) = -1;