-
Notifications
You must be signed in to change notification settings - Fork 1
/
1042.cpp
32 lines (32 loc) · 838 Bytes
/
1042.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
class Solution {
public:
void formimg(int i,vector<int>G,vector<int>&A){
bool found;
for(int f=1;f<=4;f++){
found=true;
for(int n=0;n<G.size();n++){
if(A[G[n]]!=-1 && A[G[n]]==f){
found=false;
}
}
if(found){
A[i]=f;
return ;
}
}
}
vector<int> gardenNoAdj(int N, vector<vector<int>>& paths) {
vector<int>graph[N];
for(int i=0;i<paths.size();i++){
int x=paths[i][0];
int y=paths[i][1];
graph[x-1].push_back(y-1);
graph[y-1].push_back(x-1);
}
vector<int>Answer(N,-1);
for(int i=0;i<N;i++){
formimg(i,graph[i],Answer);
}
return Answer;
}
};