Размер видео: 1280 X 720853 X 480640 X 360
Показать панель управления
Автовоспроизведение
Автоповтор
you explain very well....please keep on bringing these editorials....and please provide link to your submission
Thanks! Added link in description
iincrese volume
giving tle in 1 case
It's working. You might have written something wrong
@ I copied and pasted your code 631/632 passsed
New test case has been added
It show Tle in last two testcases
this sol does not give tleclass Solution {public: void dfs(vector& adj,string& s,vector& newadj,vector& parentCharCnt,int u){ for(int v:adj[u]){ int CharIndex = s[v]-'a'; if(parentCharCnt[CharIndex].size()>0){ int NearAncestorIndex = parentCharCnt[CharIndex].size()-1; newadj[parentCharCnt[CharIndex][NearAncestorIndex]].push_back(v); } else{ newadj[u].push_back(v); } parentCharCnt[CharIndex].push_back(v); dfs(adj,s,newadj,parentCharCnt,v); parentCharCnt[CharIndex].pop_back(); } } int CountDescendantsDfs(vector& np,int u,vector& ans){ ans[u] = 1; for(int v:np[u]){ ans[u]+=CountDescendantsDfs(np,v,ans); } return ans[u]; } vector findSubtreeSizes(vector& parent, string s) { int n = parent.size(); vector ans(n,0); vector adj(n); vector newadj(n); vector parentCharCnt(26); for(int i=1;i
increase volume
Ok
you explain very well....please keep on bringing these editorials....and please provide link to your submission
Thanks! Added link in description
iincrese volume
giving tle in 1 case
It's working. You might have written something wrong
@ I copied and pasted your code 631/632 passsed
New test case has been added
It show Tle in last two testcases
this sol does not give tle
class Solution {
public:
void dfs(vector& adj,string& s,vector& newadj,vector& parentCharCnt,int u){
for(int v:adj[u]){
int CharIndex = s[v]-'a';
if(parentCharCnt[CharIndex].size()>0){
int NearAncestorIndex = parentCharCnt[CharIndex].size()-1;
newadj[parentCharCnt[CharIndex][NearAncestorIndex]].push_back(v);
}
else{
newadj[u].push_back(v);
}
parentCharCnt[CharIndex].push_back(v);
dfs(adj,s,newadj,parentCharCnt,v);
parentCharCnt[CharIndex].pop_back();
}
}
int CountDescendantsDfs(vector& np,int u,vector& ans){
ans[u] = 1;
for(int v:np[u]){
ans[u]+=CountDescendantsDfs(np,v,ans);
}
return ans[u];
}
vector findSubtreeSizes(vector& parent, string s) {
int n = parent.size();
vector ans(n,0);
vector adj(n);
vector newadj(n);
vector parentCharCnt(26);
for(int i=1;i
increase volume
Ok