This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
.:-=++***#***+=:.
.:-==+**##**%########***#####*=:.
.-+#%%#*****############**#******#####+=:
.-*%#####********###########*********#######*+-:
:+#######**********########*****+********##########+-.
:+##########**###******##********************###########+:
:+##########*****#*******###**********************###***####*:
.=###########***###*******#***************************#****#####*:
:*#################******************************************######=
-###################***************+****************************#####*:
.=###################******************************************#****#####+.
:*###################*******************************+************#*****#####:
=#############**######*****#*******************++***++++++***************#####=
.*###########******####*****#************+++*+**+++***++++++++***#**********#####+
-############********###*****%*+****+++++++++++++++++***++++++++***#*****#****#####*
=############********###+++++##++++++++++++++++*++++++****++++******##*+++*#****#####*.
.+#*##########*********###+++++%*++==++++++++++++*+++++*#************#*##*+++##****#####*.
.*#=-##########********###*++++*%*+++++++++++++*****+******#***********#*##*+++####*######*.
.:-: .*#: *#########*********###+++++##****++*******************#*#**********##*#*****####*#%###%*.
.--:++=+. .**. ##########********##*#++***%#****+*************=#*****#*#**********##*##*##*####**#%###%*:
:++===== .**. -###########******##*##+****%#*****#************-********#**********#***%####*###***#%######=:
.-=++= =*. +############****###*##*****%#*****%####*####**#:=#***#**#**********#=##*###**####***#%########+:
. .#. .####################*##*****%#####*%#****##****#.:#***#*#**********#%:##*+##***%###***############+:
-- -###################**#*****####****##****##*****..#*****#**********#*.*#+ +##**#####***##############+-.
-=+++-. = +###################**#*****###**********#*#***#: .***#*#***********#:.*#- :**#*######***#######%%%####%%#=:
.++====++ = ####################**##*****###***#+****#=#**** .+*###************+ ## +***######****##########+--+#%%%%+:
.---:=+======+: +. ##################%#***#*****####****#**#+-####. .+###***##*******# .#: :***########***##%%%####%#=. .:=*%%
---==++=======+= -= .%#################%****#*****######-#*##*.=%#*. +=---:::.......: =: =**#########***#%%%%%%%%%%%=. .-
:-:===========+= .#. :%################%%****#*****#####= :-+***#*=. .*#########%%#**#*=%%%%%%%%%%=.
.---=========+= :*. -#################%%****#*****%#+-.-*#%%%@###*= +##########%%%***:+-#%%%#####*:
.:=++++====+- =*.=###%############%@%****#*****#. =###%%%@@@+ ###########%%%%#*#: -*########=
..:::::-. +*+###%####%######%%+******#****#=##= -@@@@@@@+ =*###########%%%%##+ :*#######+
=%##+%####%######%+.******#*****%%#-:+@@@@%-=* +..###########%##%%%*. -#######
%##=#####%###%%#%:=******#*****%*.**##*+=: . -+**####*=: - .=###############%%*: .+#####
.%###%########%%%%:.#*****##*****= .+: . :-::.:--=++- : .-*##################+: :####
:##.*###########%@# #************+ .:.-==-- . +**###+*##############*: .*##
-%- ############%@@-#*###*#=##***#. :. =*++*#**++*##############*- .##
=# ############@@@######*#:###*##= :..+*++++***+++++*##############=.+#
+: ###########%@%%%%######.=###### .=+#+++++++***+++++****##############
.+ *##########%%%%%%######::######= =+++#*+++++++*#+++++******###########
+: =%#%######%%%##%@######:-+######. .:------== :*++++**+++++++*#*+++++********#######
-* :%%%%#####%%%##%%%#####***######* -=--------=: -*+++++++*++++++++*#**+++*=:=******+==*
.*+ +%%%%###%%####%%%#####**+#######= -........:=: -++++++++++*#**##***+******++- .-******=.
-*= *%%%%##%%%%%%%#%#####**++#######. :.........- .=#%%%######%##########%#+*******. .-++++*+
-*+ .*%%%%#%%#######%#####*++++######*: ......... :=#%@@%%%%%%#################*++*****=. .-++++
:**. :###%%%#%%########%####*++++*#######=-:.. -+#%%%###########################++++****#=. .-++
-*+ .######%%%%#########%###@@@%%%%######+...:----:. :*%################################%*+++++*+###- .+
:*+.=########%%%%###########%%%%%%%%######-........:------::.+%%%%%###############%#############%*+++++*.:*##+. .
-+####****##%%%%%%%%###%########%%@%#####:.......:::::::...=@@%%%@###############%############%*+++++*. =##+
+#*##*****####%%%%##%%%%#########%@%#####:.....-:....:..::=*=++++############################%#*+++++ -##.
=%**********#######%%###############%*#####=...=. . :-=-: .###############%#******####%#####+= +*
*#************#############%%#######**+*%####-.- .-:=##############%*********##%#######=: .+.
*#****************##**######%%%###*: ::*#####: -:: .-+####%%%####%*********#%##########*-:
=#***********************######%*- .--:=:. =. :--: .-=*###%###*********#######*#######+-
.#**************************###= .:. ::... .=. +***#%##*******#########***#######+:
=##**************************: :-:--. .. .+..... + =******#%#####%##########***#####**#
####**********************+. . :#########+-=:.... -: +***********##%%#***######****##****
.#%####******************- *##########*:....... ...:. #**************##*********###*##****
:#%@%%%###************* =#*******####+....... :-. *#***************%************#%#****
.#**###%%%%%######****#. =#***********#=....:-. :*#****************##*************####*
*#**#****#####%%%%##### =#*************+=: .=-::..:-*#*****************##*****************##
-#***#*******######%%%%= :=*#**********: ... ##*##%##*******************#********************
.%*****#*********######%. ....:-=*- :++: =#****##%####*************###********************
:. +#*****#**********####%+ ..-*#***#+=##*******##%%###********####*********************
.:-:. .%#*****#**********#%%%* :=+**##########******###********#%%%%%%##****###***********************
-- =%#******#*********@#%%-. :#%%%%%%%%%%%%%%###*****###*****#%%##%%%#%@#####*************************
=-. .=. ##*******#********#%#**###*+=-:.: -######%##%###%####%%%%%##########%####%%%%##%*************####************
==== .= :%#*******#********%%***************++#%%#%#######%###%#######%%%%%%%########%%%%####%#************####***********
==== -: *%#*******#********@#********************#%#######%###%###########%%%%%#####%%%#######%%#**********#####**********
:+=+. = .%###*******#******#%#*******************#%#############%##############%%%##%######***####%%#*******######*********
*/
#include <bits/stdc++.h>
using namespace std;
int solve(int N, int M, vector<int> F, vector<vector<int>> S)
{
deque<int> toprocess;
unordered_set<int> globalseen = {0};
vector<unordered_set<int>> seen = {{},{},{},{},{}};
vector<int> processed = {1,1,1,1,1};
vector<int> tempchildren;
for(int i=0; i<N; i++)
{
tempchildren.push_back(0);
}
for(int i=1; i<N; i++)
{
tempchildren[F[i]]+=1;
}
vector<vector<int>> children;
for(int i=0; i<M; i++)
{
vector<int> temparr;
temparr = tempchildren;
children.push_back(temparr);
}
int ans = 0;
for(int j=0; j<(N-1); j++)
{
bool check = true;
for(int i=0; i<M; i++)
{
//i
int num = S[i][j];
deque<int>().swap(toprocess);
globalseen.insert(num);
seen[i].insert(num);
toprocess.push_back(num);
while(toprocess.size())
{
num = toprocess[0];
toprocess.pop_front();
if(children[i][num] == 0)
{
children[i][F[num]] -=1 ;
processed[i] += 1;
if(children[i][F[num]] == 0 && seen[i].find(F[num])!=seen[i].end())
{
toprocess.push_back(F[num]);
}
}
}
check &= (processed[i]==globalseen.size());
}
if(check)
{
ans++;
}
}
return ans;
};
/*
int main()
{
cout << solve(3, 1, {-1, 0, 0}, {{1, 2}}) << endl;
cout << solve(5, 2, {-1, 0, 0, 1, 1}, {{1, 2, 3, 4}, {4, 1, 2, 3}}) << endl;
return 0;
}
*/
Compilation message (stderr)
september.cpp: In function 'int solve(int, int, std::vector<int>, std::vector<std::vector<int> >)':
september.cpp:123:36: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::unordered_set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
123 | check &= (processed[i]==globalseen.size());
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |