제출 #1318857

#제출 시각아이디문제언어결과실행 시간메모리
1318857g31niusEaster Eggs (info1cup17_eastereggs)C++20
10 / 100
2 ms484 KiB
#include <vector> using namespace std; int query(vector<int> islands); vector<vector<int>> adj; vector<int> subtree; void dfs(int node, int parent) { subtree.push_back(node); for (int next : adj[node]) { if (next != parent) { dfs(next, node); } } } int findEgg(int N, vector<pair<int, int>> bridges) { // Build adjacency list adj.assign(N + 1, vector<int>()); for (auto& edge : bridges) { adj[edge.first].push_back(edge.second); adj[edge.second].push_back(edge.first); } // Start from node 1 int current = 1; int parent = -1; while (true) { // Check all children subtrees of current node bool foundInChild = false; for (int neighbor : adj[current]) { if (neighbor == parent) continue; // Skip parent // Get all nodes in this child's subtree subtree.clear(); dfs(neighbor, current); // Query this subtree if (query(subtree) == 1) { // Egg is in this subtree, move to it parent = current; current = neighbor; foundInChild = true; break; } } // If egg not in any child subtree, it's at current node if (!foundInChild) { return current; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...