Last active
November 1, 2018 02:44
-
-
Save Indp-Dustin/5a170b6b1015f596feac0076416c94b5 to your computer and use it in GitHub Desktop.
Trio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "pch.h" | |
#include <iostream> | |
#include <vector> | |
int dustinBestTrio(int friend_nodes, int friends_from[], int friends_to[]) | |
{ | |
std::vector<std::vector<int>> allfriends(friend_nodes); | |
int i = 0; | |
int f = friends_from[i]; | |
int t = friends_to[i]; | |
while (f >= 0) | |
{ | |
if (f == t) | |
{ | |
std::cout << "from should not equal to to" << std::endl; | |
break; | |
} | |
allfriends[f].push_back(t); | |
allfriends[t].push_back(f); | |
i++; | |
f = friends_from[i]; | |
t = friends_to[i]; | |
} | |
int highscore = -1; | |
for(int self = 0; self < allfriends.size(); self++) | |
{ | |
for(int n = 0; n < allfriends[self].size(); n++) | |
{ | |
int nextfriend = allfriends[self][n]; | |
for(int sn = 0; sn < allfriends[nextfriend].size(); sn++) | |
{ | |
int friendsinnextfriend = allfriends[nextfriend][sn]; | |
if (friendsinnextfriend == self) | |
{ | |
// Duo | |
continue; | |
} | |
for(int tn = 0; tn < allfriends[friendsinnextfriend].size(); tn++) | |
{ | |
int friendsinnextnextfriend = allfriends[friendsinnextfriend][tn]; | |
if (friendsinnextnextfriend == self) | |
{ | |
// Trio! | |
int score = (allfriends[self].size() - 2) + (allfriends[nextfriend].size() - 2) + (allfriends[friendsinnextfriend].size() - 2); | |
if (score > highscore) | |
{ | |
highscore = score; | |
} | |
continue; | |
} | |
} | |
} | |
} | |
} | |
return highscore; | |
} | |
int main() | |
{ | |
int from[] = { 0, 1, 3, 1, 2, 5, -1 }; | |
int to[] = { 1, 3, 4, 4, 4, 4, -1 }; | |
std::cout << dustinBestTrio(6, from, to) << std::endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
int dustinBestTrio(int friend_nodes, int friends_from[], int friends_to[]); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment