Skip to content

Commit 1b710eb

Browse files
author
Prateek Narang
committed
added java code
1 parent f50b6d2 commit 1b710eb

File tree

151 files changed

+4159
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+4159
-0
lines changed

.DS_Store

2 KB
Binary file not shown.

Graphs C++/.DS_Store

0 Bytes
Binary file not shown.

Graphs Java/.DS_Store

8 KB
Binary file not shown.

Graphs Java/.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Graphs Java/.idea/kotlinc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Graphs Java/.idea/libraries/KotlinJavaRuntime.xml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Graphs Java/.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Graphs Java/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Graphs Java/.idea/uiDesigner.xml

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Graphs Java/Graphs.iml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
11+
</component>
12+
</module>

Graphs Java/out/.DS_Store

6 KB
Binary file not shown.

Graphs Java/out/production/.DS_Store

6 KB
Binary file not shown.
8 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package ArticulationPointAndBridges;
2+
3+
import java.util.ArrayList;
4+
import java.util.HashSet;
5+
import java.util.Scanner;
6+
import java.util.Set;
7+
8+
public class ArticulationPointAndBridges {
9+
10+
static class Pair{
11+
int first, second;
12+
13+
Pair(int a, int b){
14+
first = a;
15+
second = b;
16+
}
17+
}
18+
19+
static final int N = (int) (1e5 + 1);
20+
21+
static ArrayList<Integer>[] gr = new ArrayList[N];
22+
static Set<Integer> arti_points = new HashSet<>();
23+
static {
24+
for(int i = 0 ; i < N ; i++){
25+
gr[i] = new ArrayList<>();
26+
}
27+
}
28+
29+
static int tme = 1;
30+
static boolean[] vis = new boolean[N];
31+
static int[] disc = new int[N];
32+
static int[] low = new int[N];
33+
34+
static ArrayList<Pair> bridges = new ArrayList<>();
35+
36+
static void dfs(int cur, int par) {
37+
vis[cur] = true;
38+
disc[cur] = low[cur] = tme++;
39+
int child = 0;
40+
for (int x : gr[cur]) {
41+
42+
if (!vis[x]) {
43+
dfs(x, cur);
44+
child++;
45+
// we know low and disc of x
46+
low[cur] = Math.min(low[cur], low[x]);
47+
48+
// bridges
49+
if (low[x] > disc[cur]) {
50+
bridges.add(new Pair(cur, x));
51+
}
52+
53+
// articulation points
54+
if (par != 0 && low[x] >= disc[cur]) {
55+
arti_points.add(cur);
56+
}
57+
58+
}
59+
else if (x != par) {
60+
// backedge
61+
low[cur] = Math.min(low[cur], disc[x]);
62+
}
63+
}
64+
65+
// root is an arti or not
66+
if (par == 0 && child > 1) {
67+
arti_points.add(cur);
68+
}
69+
70+
}
71+
72+
73+
public static void main(String[] args)
74+
{
75+
Scanner scn = new Scanner(System.in);
76+
int n = scn.nextInt(), m = scn.nextInt();
77+
78+
for (int i = 0; i < m; i++) {
79+
int x = scn.nextInt(), y = scn.nextInt();
80+
gr[x].add(y);
81+
gr[y].add(x);
82+
83+
}
84+
85+
dfs(1, 0);
86+
87+
for (int x : arti_points) System.out.println(x);
88+
89+
for (Pair x : bridges) {
90+
System.out.println( x.first + " " + x.second );
91+
}
92+
93+
}
94+
}

0 commit comments

Comments
 (0)