565. Array Nesting(dfs 血的教训)

为什么说是血的教训呢,因为明明自己想的思路与那些AC的人思路一样

而自己偏偏超时,又爆内存,觉得很奇怪,偏偏又找不出问题所在

这道题,看完题意就知道dfs的思路了,却因为很小的细节卡了我2个小时!!!!! 泪崩

先看题目:

A zero-indexed array A consisting of N different integers is given. The array contains all integers in the range [0, N - 1].

Sets S[K] for 0 <= K < N are defined as follows:

S[K] = { A[K], A[A[K]], A[A[A[K]]], ... }.

Sets S[K] are finite for each K and should NOT contain duplicates.

Write a function that given an array A consisting of N integers, return the size of the largest set S[K] for this array.

Example 1:

Input: A = [5,4,0,3,1,6,2]
Output: 4
Explanation: 
A[0] = 5, A[1] = 4, A[2] = 0, A[3] = 3, A[4] = 1, A[5] = 6, A[6] = 2.
One of the longest S[K]: S[0] = {A[0], A[5], A[
17:24:40 **** Build of configuration gcc-debug for project nesting **** make MODE=debug -j16 all cd src && /usr/bin/make make[1]: Entering directory '/c/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/samples/nesting-master/nesting-master/src' MSGC: nesting/common/FlowMetaTag.msg MSGC: nesting/ieee8021q/queue/framePreemption/ExpressFrameTag.msg MSGC: nesting/linklayer/common/VLANTagDeprecated.msg MSGC: nesting/linklayer/framePreemption/PreemptedFrame.msg MSGC: nesting/linklayer/vlan/EnhancedVlanTag.msg nesting/application/ethernet/VlanEtherTrafGenSched.cc nesting/application/inet/VlanRequester.cc nesting/application/udpapp/DatagramScheduleManager.cc nesting/application/ethernet/VlanEtherTrafGen.cc nesting/application/udpapp/SendDatagramEvent.cc nesting/application/udpapp/UdpReactiveApp.cc nesting/application/udpapp/UdpScheduledTrafficGenerator.cc nesting/common/ResultFilters.cc nesting/common/schedule/CycleTimerState.cc nesting/common/schedule/GateScheduleManager.cc nesting/common/schedule/HostScheduleBuilder.cc nesting/common/schedule/ListExecuteState.cc nesting/common/schedule/ListConfigState.cc nesting/common/schedule/ScheduleFactory.cc nesting/common/time/IdealOscillator.cc nesting/common/time/LegacyClock.cc nesting/common/time/OscillatorBase.cc nesting/common/time/RealtimeClock.cc nesting/ieee8021q/queue/QueuingFrames.cc In file included from nesting/application/udpapp/DatagramScheduleManager.cc:16: In file included from .\nesting/application/udpapp/DatagramScheduleManager.h:21: .\nesting/common/schedule/ScheduleManager.h:162:27: warning: unused variable 'idleTime' [-Wunused-variable] simtime_t idleTime = cycleStartTime - clock->updateAndGetLocalTime(); ^ In file included from nesting/common/ResultFilters.cc:16: .\nesting/common/ResultFilters.h:29:18: warning: 'nesting::FlowIdFilter::receiveSignal' hides overloaded virtual functions [-Woverloaded-virtual] virtual void receiveSignal(cResultFilter* prev, simtime_t_cref t, cObject* object, cObject* details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:134:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('bool' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:135:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('long' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, long l, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:136:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('unsigned long' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, unsigned long l, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:137:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('double' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:138:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('const omnetpp::SimTime &' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:139:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('const char *' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override; ^ In file included from nesting/common/ResultFilters.cc:16: .\nesting/common/ResultFilters.h:39:18: warning: 'nesting::SeqNumFilter::receiveSignal' hides overloaded virtual functions [-Woverloaded-virtual] virtual void receiveSignal(cResultFilter* prev, simtime_t_cref t, cObject* object, cObject* details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:134:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('bool' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:135:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('long' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, long l, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:136:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('unsigned long' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, unsigned long l, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:137:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('double' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:138:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('const omnetpp::SimTime &' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:139:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('const char *' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override; ^ In file included from nesting/application/inet/VlanRequester.cc:19: .\nesting/linklayer/vlan/EnhancedVlanTag_m.h:20:10: fatal error: 'inet/linklayer/vlan/VlanTag_m.h' file not found #include "inet/linklayer/vlan/VlanTag_m.h" ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from nesting/application/udpapp/DatagramScheduleManager.cc:16: .\nesting/application/udpapp/DatagramScheduleManager.h:41:18: warning: 'nesting::DatagramScheduleManager::initialize' hides overloaded virtual function [-Woverloaded-virtual] virtual void initialize(int stage) override;1 error generated. ^ .\nesting/common/schedule/ScheduleManager.h:101:18: note: hidden overloaded virtual function 'nesting::ScheduleManager<nesting::SendDatagramEvent>::initialize' declared here: different number of parameters (0 vs 1) virtual void initialize() override ^ In file included from nesting/application/ethernet/VlanEtherTrafGen.cc:17: .\nesting/linklayer/vlan/EnhancedVlanTag_m.h:20:10: fatal error: 'inet/linklayer/vlan/VlanTag_m.h' file not found #include "inet/linklayer/vlan/VlanTag_m.h" ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ make[1]: *** [Makefile:153: ../out/clang-debug/src/nesting/application/inet/VlanRequester.o] Error 1 make[1]: *** Waiting for unfinished jobs.... In file included from nesting/common/schedule/GateScheduleManager.cc:16: In file included from .\nesting/common/schedule/GateScheduleManager.h:19: .\nesting/common/schedule/ScheduleManager.h:162:27: warning: unused variable 'idleTime' [-Wunused-variable] simtime_t idleTime = cycleStartTime - clock->updateAndGetLocalTime(); ^ In file included from nesting/application/udpapp/UdpScheduledTrafficGenerator.cc:16: In file included from .\nesting/application/udpapp/UdpScheduledTrafficGenerator.h:25: In file included from .\nesting/application/udpapp/DatagramScheduleManager.h:21: .\nesting/common/schedule/ScheduleManager.h:162:27: warning: unused variable 'idleTime' [-Wunused-variable] simtime_t idleTime = cycleStartTime - clock->updateAndGetLocalTime(); ^ In file included from nesting/application/udpapp/UdpScheduledTrafficGenerator.cc:16: In file included from .\nesting/application/udpapp/UdpScheduledTrafficGenerator.h:25: .\nesting/application/udpapp/DatagramScheduleManager.h:41:18: warning: 'nesting::DatagramScheduleManager::initialize' hides overloaded virtual function [-Woverloaded-virtual] virtual void initialize(int stage) override; ^ .\nesting/common/schedule/ScheduleManager.h:101:18: note: hidden overloaded virtual function 'nesting::ScheduleManager<nesting::SendDatagramEvent>::initialize' declared here: different number of parameters (0 vs 1) virtual void initialize() override ^ In file included from nesting/application/udpapp/UdpScheduledTrafficGenerator.cc:16: .\nesting/application/udpapp/UdpScheduledTrafficGenerator.h:51:18: warning: 'initialize' overrides a member function but is not marked 'override' [-Winconsistent-missing-override] virtual void initialize(int stage); ^ ../../../inet/src\inet/common/lifecycle/OperationalBase.h:52:18: note: overridden virtual function is here virtual void initialize(int stage) override; ^ In file included from nesting/application/udpapp/UdpScheduledTrafficGenerator.cc:17: .\nesting/linklayer/vlan/EnhancedVlanTag_m.h:20:10: fatal error: 'inet/linklayer/vlan/VlanTag_m.h' file not found #include "inet/linklayer/vlan/VlanTag_m.h" ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. 3 warnings and 1 error generated. make[1]: *** [Makefile:151: ../out/clang-debug/src/nesting/application/ethernet/VlanEtherTrafGen.o] Error 1 In file included from nesting/application/ethernet/VlanEtherTrafGenSched.cc:16: .\nesting/application/ethernet/VlanEtherTrafGenSched.h:88:18: warning: 'nesting::VlanEtherTrafGenSched::sendDelayed' hides overloaded virtual functions [-Woverloaded-virtual] virtual void sendDelayed(cMessage *msg); ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include/omnetpp/csimplemodule.h:215:18: note: hidden overloaded virtual function 'omnetpp::cSimpleModule::sendDelayed' declared here: different number of parameters (3 vs 1) virtual void sendDelayed(cMessage *msg, simtime_t delay, int gateid); ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include/omnetpp/csimplemodule.h:222:18: note: hidden overloaded virtual function 'omnetpp::cSimpleModule::sendDelayed' declared here: different number of parameters (4 vs 1) virtual void sendDelayed(cMessage *msg, simtime_t delay, const char *gatename, int gateindex=-1); ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include/omnetpp/csimplemodule.h:228:18: note: hidden overloaded virtual function 'omnetpp::cSimpleModule::sendDelayed' declared here: different number of parameters (3 vs 1) virtual void sendDelayed(cMessage *msg, simtime_t delay, cGate *outputgate); ^ In file included from nesting/application/ethernet/VlanEtherTrafGenSched.cc:17: .\nesting/linklayer/vlan/EnhancedVlanTag_m.h:20:10: fatal error: 'inet/linklayer/vlan/VlanTag_m.h' file not found #include "inet/linklayer/vlan/VlanTag_m.h" ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ make[1]: *** [Makefile:151: ../out/clang-debug/src/nesting/application/udpapp/UdpScheduledTrafficGenerator.o] Error 1 1 warning and 1 error generated. make[1]: *** [Makefile:151: ../out/clang-debug/src/nesting/application/ethernet/VlanEtherTrafGenSched.o] Error 1 nesting/common/schedule/GateScheduleManager.cc:58:15: warning: unused variable 'sumTimeIntervals' [-Wunused-variable] simtime_t sumTimeIntervals = schedule.getSumTimeIntervals(); ^ nesting/common/schedule/GateScheduleManager.cc:57:14: warning: unused variable 'cycleTime' [-Wunused-variable] uint64_t cycleTime = schedule.getControlListLength(); ^ 2 warnings generated. 2 warnings generated. nesting/common/time/OscillatorBase.cc:26:7: warning: field 'timeOfLastTick' will be initialized after field 'tickEventNow' [-Wreorder] , timeOfLastTick(SimTime::ZERO) ^ nesting/common/time/OscillatorBase.cc:119:18: warning: unused variable 'elapsedTicks' [-Wunused-variable] uint64_t elapsedTicks = currentTick - lastTick; ^ In file included from nesting/ieee8021q/queue/QueuingFrames.cc:16: .\nesting/ieee8021q/queue/QueuingFrames.h:23:10: fatal error: 'inet/linklayer/vlan/VlanTag_m.h' file not found #include "inet/linklayer/vlan/VlanTag_m.h" ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from nesting/common/time/RealtimeClock.cc:16: .\nesting/common/time/RealtimeClock.h:74:18: warning: 'initialize' overrides a member function but is not marked 'override' [-Winconsistent-missing-override] virtual void initialize(); ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include/omnetpp/ccomponent.h:238:18: note: overridden virtual function is here virtual void initialize(); ^ nesting/common/time/RealtimeClock.cc:28:7: warning: field 'nextTick' will be initialized after field 'driftRate' [-Wreorder] , nextTick(nullptr) ^ nesting/common/time/RealtimeClock.cc:29:7: warning: field 'driftRate' will be initialized after field 'lastTick' [-Wreorder] , driftRate(0.0) ^ nesting/common/time/RealtimeClock.cc:245:7: warning: field 'listener' will be initialized after field 'localTime' [-Wreorder] : listener(listener) ^ 3 warnings generated. 1 error generated. make[1]: *** [Makefile:151: ../out/clang-debug/src/nesting/ieee8021q/queue/QueuingFrames.o] Error 1 2 warnings generated. 4 warnings generated. make[1]: Leaving directory '/c/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/samples/nesting-master/nesting-master/src' make: *** [Makefile:11: all] Error 2 "make MODE=debug -j16 all" terminated with exit code 2. Build might be incomplete.
最新发布
10-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值