-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadjList_directed_graph.cpp
More file actions
38 lines (33 loc) · 930 Bytes
/
Copy pathadjList_directed_graph.cpp
File metadata and controls
38 lines (33 loc) · 930 Bytes
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
#include <iostream>
#include <vector>
using namespace std;
// you have to implement the mostInfluentialUser() only
int mostInfluentialUser(const vector<int> &influenceScore) {
int maxScore = -1;
int userIndex = -1;
for (int i = 0; i < influenceScore.size(); i++) {
if (influenceScore[i] > maxScore) {
maxScore = influenceScore[i];
userIndex = i;
} else if (influenceScore[i] == maxScore && i < userIndex) {
userIndex = i; // Tie-breaking by smaller index
}
}
return userIndex;
}
int main() {
// Read input
int n, m;
cin >> n >> m;
vector<int> influenceScore(n, 0);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
if (u != v) {
influenceScore[v]++;
}
}
// please don't change the main function
cout << mostInfluentialUser(influenceScore);
return 0;
}