-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2017 Week 3.java
119 lines (106 loc) · 2.77 KB
/
2017 Week 3.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//Matthew Farias
//Filtering Uncool Kats
//2017 Week 3
//link to problem: https://potw.cs.uwindsor.ca/problem/2017/3
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main{
public static void main(String[]args){
Scanner kb = new Scanner(System.in);
int n= kb.nextInt();
kb.nextLine();
Map<Integer, User>map=new HashMap<>();
String line;
String[]split;
int a,b,c;
for(int i=0;i<n;i++){
line=kb.nextLine();
split=line.split(" ");
a=Integer.parseInt(split[0]);
b=Integer.parseInt(split[1]);
if(!map.containsKey(a)){
map.put(a, new User(a));
}
if(!map.containsKey(b)){
map.put(b, new User(b));
}
map.get(a).addFriend(map.get(b));
map.get(b).addFriend(map.get(a));
}
n=kb.nextInt();
kb.nextLine();
Map<Integer, Post>map2=new HashMap<>();
ArrayList<Integer>postids=new ArrayList<>();
for(int i=0;i<n;i++){
line=kb.nextLine();
split=line.split(" ");
a=Integer.parseInt(split[0]);
b=Integer.parseInt(split[1]);
c=Integer.parseInt(split[2]);
if(!map2.containsKey(b)){
map2.put(b,new Post((b)));
postids.add(b);
}
if(c==1){
map2.get(b).like(map.get(a));
}
else{
map2.get(b).dislike(map.get(a));
}
}
Post tmp;
int count;
line=kb.nextLine();
split=line.split(" ");
a=Integer.parseInt(split[0]);
b=Integer.parseInt(split[1]);
for(int p: postids){
tmp=map2.get(p);
tmp.valid(map.get(a),b);
}
}
}
class User{
private int id;
private ArrayList<User>friends;
public User(int n){
id=n;
friends=new ArrayList<>();
}
public void addFriend(User u){
friends.add(u);
}
public int getId(){
return id;
}
public ArrayList<User> getFriends() {
return friends;
}
}
class Post{
private int id, count;
private ArrayList<User>likedby=new ArrayList<>();
private ArrayList<User>dislikedby=new ArrayList<>();
public Post(int n){
id=n;
}
public void like(User u){
likedby.add(u);
}
public void dislike(User u){
dislikedby.add(u);
}
public void valid(User u, int n){
count=0;
for(User user : u.getFriends()){
if(likedby.contains(user))
count++;
else if(dislikedby.contains(user))
count--;
}
if(count>=n)
System.out.println(id);
}
}