-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsp.cpp
50 lines (49 loc) · 1.14 KB
/
sp.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<bits/stdc++.h>
using namespace std;
int solution(vector<int> friends) {
vector<vector<int>> a(friends.size()) ;
for(int i = 0 ; i < friends.size() ; i++)
{
vector<int> b = {i,2,true} ;
a[i] = b ;
}
int no = friends.size() ;
for(int j = 0 ; j < friends.size() ; j++)
{
if(j==friends[j])
{
continue ;
}
if( a[friends[j]][1] >0 && a[j][1]>0 && a[j][2] == true)
{
a[friends[j]][1]-- ;
a[j][1]-- ;
if(friends[friends[j]]==j)
{
a[friends[j]][2] = false ;
// a[friends[j]][1]++ ;
// a[j][1]++ ;
}
continue ;
}
if(a[friends[j]][1] >0 && a[j][1]>0 && a[j][2] == false)
{
continue ;
}
no-- ;
}
for( int j = 0 ; j < a.size() ; j++)
{
for(int i = 0 ; i < a[j].size() ; i++)
{
cout<<a[j][i]<<" " ;
}
cout<<endl ;
}
return no ;
}
int main()
{
vector<int> a = {1, 2, 0, 4, 3, 5, 6, 8, 7} ;
cout<<solution(a) ;
}