forked from DionysiosB/CodeForces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
159A-FriendsOrNot.cpp
50 lines (37 loc) · 1.75 KB
/
159A-FriendsOrNot.cpp
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
#include <cstdio>
#include <iostream>
#include <string>
#include <set>
#include <vector>
int main(){
int n(0), d(0); scanf("%d %d", &n, &d);
std::string source(""), dest(""); int messageTime(0);
std::vector<std::pair<std::string, std::string>> people;
std::vector<int> times;
std::set<std::pair<std::string, std::string>> friends;
for(int k = 0; k < n; k++){
std::cin >> source >> dest >> messageTime;
std::pair<std::string, std::string> messagePeople(source,dest);
people.push_back(messagePeople);
times.push_back(messageTime);
}
for(int before = 0; before < n; before++){
std::string sourceBefore = people[before].first;
std::string destBefore = people[before].second;
int timeBefore = times[before];
for(int after = before + 1; after < n; after++){
std::string sourceAfter = people[after].first;
std::string destAfter = people[after].second;
int timeAfter = times[after];
if(timeAfter > timeBefore && timeAfter - timeBefore <= d && sourceBefore == destAfter && destBefore == sourceAfter){
if(friends.find(std::pair<std::string, std::string>(sourceBefore, destBefore)) == friends.end() && friends.find(std::pair<std::string, std::string>(destBefore, sourceBefore)) == friends.end()){
friends.insert(std::pair<std::string, std::string>(sourceBefore, destBefore));
}
}
}
}
printf("%ld\n", friends.size());
std::set<std::pair<std::string, std::string>>::iterator pairIter;
for(pairIter = friends.begin(); pairIter != friends.end(); pairIter++){std::cout << pairIter->first << " " << pairIter->second << std::endl;}
return 0;
}