17 {
21 for(
int i = 0; i <
N; i++) {
22 Student *stu = new Student(i);
23 stu->c_priority = unordered_map<Company *, int>();
24 stu->priority_c = unordered_map<int, Company *>();
26 Company *com = new Company(i);
27 com->priority = unordered_map<Student *, int>();
29 }
30 for(
int i = 0; i <
N; i++) {
31 for(
int j = 0; j <
N; j++) {
35 }
36 }
37 bool flag = true;
38 while(flag) {
39 flag = false;
40 for(
int i = 0; i <
N; i++) {
42 if(stu->matched_company == nullptr) {
43 flag = true;
44 stu->priority_c[stu->current_priority++]->proposed_students.insert(stu);
45 }
46 }
47
48 for(
int i = 0; i <
N; i++) {
50 Student *current_matched_student = com->matched_student;
51 if(com->proposed_students.size() > 0) {
52 int min_priority = com->matched_student ? com->priority[com->matched_student] : INT_MAX;
53 Student *max_p_student = com->matched_student;
54 for(auto stu: com->proposed_students) {
55 if(com->priority[stu] < min_priority) {
56 min_priority = com->priority[stu];
57 max_p_student = stu;
58 flag = true;
59 }
60 }
61 if(flag) {
62 if(current_matched_student != nullptr) {
63 current_matched_student->matched_company = nullptr;
64 }
65 com->matched_student = max_p_student;
66 max_p_student->matched_company = com;
67 }
68 com->proposed_students.clear();
69 }
70 }
71 }
72 vector<int>
ans = vector<int>(N, -1);
73 for(
int i = 0; i <
N; i++) {
75 }
77 }
vector< vector< int > > ans
vector< Student * > students
vector< Company * > companies