Submission #128232

#TimeUsernameProblemLanguageResultExecution timeMemory
128232zeyad49Pipes (CEOI15_pipes)Java
10 / 100
186 ms65540 KiB
import java.io.*; import java.util.*; public class pipes { static ArrayList<Integer>[] adjList; static int[] dfs_low, dfs_num, parent; static int V, counter; static PrintWriter out = new PrintWriter(System.out); static int [][]cnt; public static void main(String[] args) throws IOException { Scanner sc = new Scanner(); V = sc.nextInt(); cnt=new int [V][V]; adjList = new ArrayList[V]; for (int i = 0; i < V; i++) adjList[i] = new ArrayList(); int m = sc.nextInt(); while (m-- > 0) { int u = sc.nextInt() - 1, v = sc.nextInt() - 1; adjList[u].add(v); adjList[v].add(u); cnt[u][v]++; cnt[v][u]++; } dfs_low = new int[V]; dfs_num = new int[V]; parent = new int[V]; findArtPointsAndBridges(); out.close(); } static void findArtPointsAndBridges() // O(V + E) { for (int i = 0; i < V; ++i) if (dfs_num[i] == 0) { dfs(i); } } static void dfs(int u) { dfs_num[u] = dfs_low[u] = ++counter; for (int v : adjList[u]) if (dfs_num[v] == 0) { parent[v] = u; dfs(v); if (dfs_low[v] > dfs_num[u] && cnt[u][v]==1) out.printf("%d %d%n", u + 1, v + 1); dfs_low[u] = Math.min(dfs_low[v], dfs_low[u]); } else if (parent[u] != v) dfs_low[u] = Math.min(dfs_low[u], dfs_num[v]); } static class Scanner { BufferedReader br; StringTokenizer st; Scanner() { br = new BufferedReader(new InputStreamReader(System.in)); } Scanner(String fileName) throws FileNotFoundException { br = new BufferedReader(new FileReader(fileName)); } String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } String nextLine() throws IOException { return br.readLine(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws NumberFormatException, IOException { return Long.parseLong(next()); } double nextDouble() throws NumberFormatException, IOException { return Double.parseDouble(next()); } boolean ready() throws IOException { return br.ready(); } } }

Compilation message (stderr)

Note: pipes.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...