Register
|
Login
Home
News
Competitions
Practice
How to
Rankings
Calendar
Arena
CodeFu 2007
CodeFu'07 Highlights
Jazoon'07 Highlights
Schedule
Rules
Prizes
Results
Competitions
»
Main CodeFu Competitons
»
CodeFu 2007
»
Results
CodeFu 2007 Results
CodeFu Final Round Results
npostolov's solution for 500: NewsFlow, written in Java
import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; public class NewsFlow { int [] level; public int minutes(String[] willing) { int [][]v = new int[willing.length][willing.length]; for (int i = 0; i < willing.length; i++) { for (int j = 0; j < willing[i].length(); j++) { if (willing[i].charAt(j)=='Y'){ v[i][j] = 1; } } } if (bfs(v) != willing.length){ return -1; } Arrays.sort(level); return level[level.length-1]; } private int bfs(int[][] v) { boolean []used = new boolean[v.length]; level = new int[v.length]; Queue q = new LinkedList(); q.offer(new Integer(0)); used[0] = true; level[0] = 0; while (!q.isEmpty()){ int x = ((Integer)q.poll()).intValue(); for (int i=0;i<v.length;i++){ if (v[x][i]==1&&!used[i]){ q.offer(new Integer(i)); level[i] = level[x] + 1; used[i] = true; } } } int c = 0; for (int i=0;i<v.length;i++){ if (used[i]){ c++; } } return c; } private void solve(int i) { // TODO Auto-generated method stub } public static void main(String[] args) { } }