Re: [閒聊] 每日LeetCode已回收

看板Marginalman作者 (神楽めあ的錢包)時間1年前 (2024/02/24 03:13), 1年前編輯推噓1(100)
留言1則, 1人參與, 1年前最新討論串712/719 (看更多)
※ 引述《wu10200512 (廷廷)》之銘言: : 我她媽就用了一個map一個queue : 記憶體就爆了 : 他這限制也抓太緊 : 操機掰哩 還medium : 改一個小時還是改不出來 : 明天再看看 : == : 787. Cheapest Flights Within K Stops : class Solution { : public: : int findCheapestPrice(int n, vector<vector<int>>& flights, int src, int : dst, int k) { : unordered_map<int, vector<pair<int, int>>> mp; : for(auto& f:flights){ : mp[f[0]].push_back({f[1],f[2]}); : } : int ans=INT_MAX; : queue<pair<int, int>> q; : q.push({src,0}); : while(!q.empty() && k-->=0){ : int n=q.size(); : for(int i=0; i<n; i++){ : auto temp=q.front(); : q.pop(); : for(auto& v:mp[temp.first]){ : if(ans<=temp.second+v.second) continue; : if(v.first==dst) { : ans=min(ans, temp.second+v.second); : continue; : } : q.push({v.first, temp.second+v.second}); : } : } : } : if(ans==INT_MAX) return -1; : return ans; : } : }; if(ans<=temp.second+v.second) continue 你應該是錯在這一行,條件要改一下 改一下試試看 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.73.133.158 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1708715598.A.F38.html ※ 編輯: JIWP (42.73.133.158 臺灣), 02/24/2024 03:21:10

02/24 09:44, 1年前 , 1F
我等等來改 感恩的心
02/24 09:44, 1F
文章代碼(AID): #1bsEvEyu (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1bsEvEyu (Marginalman)