Untitled
unknown
c_cpp
a year ago
661 B
18
Indexable
// Online C++ compiler to run C++ program online
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int maxWeightCell(int n, vector<int> edge){
vector<int> cnt(n,0);
for(int i=0; i<n; i++){
if(edge[i] != -1)
cnt[edge[i]] += i;
}
int ans = -1;
int maxi = INT_MIN;
for(int i=0; i<n; i++){
if(maxi <= cnt[i]){
maxi = cnt[i];
ans = i;
}
}
return ans;
}
int main()
{
int n;
cin >> n;
vector<int> edges(n);
for (int i = 0; i < n; ++i)
{
cin >> edges[i];
}
cout<<maxWeightCell(n, edges)<<endl;
return 0;
}Editor is loading...
Leave a Comment