-
Notifications
You must be signed in to change notification settings - Fork 0
/
seven.java
64 lines (53 loc) · 1.5 KB
/
seven.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.io.*;
import java.util.*;
class one {
static int counter = 0;
HashMap<String, Integer> codename = new HashMap<String, Integer>();
public static void main(String[] args) throws Exception {
String line;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Hashmap<Integer, Vertex> hm = new HashMap<Integer, Vertex>();
while((line=reader.readLine())!=null) {
String [] token = line.split(" ");
if(token[0].equals("add")){
int n = getId(Integer.parseInt(token[1]));
int m = getId(Integer.parseInt(token[2]));
Vertex v, u;
if(hm.get(n) == null && hm.get(m) == null){
v = new Vertex(n);
u = new Vertex(m);
v.addneighbor(new pair(u, 1));
u.addneighbor(new pair(v, 1));
}
}
}
}
public static int getId(String name){
if(hm.get(name) == null){
hm.put(name, counter);
int save = counter;
counter++;
return save;
}
return hm.get(name);
}
static class pair<V,E>{
V vertex;
E edge;
public pair(V v, E e){
vertex = v;
edge = e;
}
}
static class Vertex implements Comparable<Vertex>{
int id;
ArrayList<pair<Vertex, Integer>> neighbor = new ArrayList<pair<Vertex, Integer>>();
int dist = Integer.MAX_VALUE;
boolean visit = false;
Vertex from;
Vertex to;
public Vertex(int i){ id = i; }
public void reset() { dist = Integer.MAX_VALUE; visit = false; from = null; }
public void addNeighbor(pair<Vertex, Integer> p) {neighbor.add(p);}
}
}