Submission #60013

#TimeUsernameProblemLanguageResultExecution timeMemory
60013Eae02Duathlon (APIO18_duathlon)C++14
0 / 100
248 ms19328 KiB
#include <bits/stdc++.h> struct Node { std::vector<int> connected; std::vector<int> children; int totalChildren; bool visited = false; }; std::vector<Node> nodes; int genTree(int i) { nodes[i].totalChildren = 0; for (int c : nodes[i].connected) { if (!nodes[c].children.empty()) continue; nodes[i].children.push_back(c); nodes[i].totalChildren += genTree(c); } return nodes[i].totalChildren + 1; } uint64_t memo[100000][2]; uint64_t count(int n, bool placedM) { uint64_t& m = memo[n][placedM ? 1 : 0]; if (m != 0) return m - 1; nodes[n].visited = true; uint64_t x = placedM ? 1 : 0; for (int i : nodes[n].connected) { if (nodes[i].visited) continue; if (!placedM) x += count(i, false); x += count(i, true); } nodes[n].visited = false; m = x + 1; return x; } int main() { int numNodes, numEdges; std::cin >> numNodes; std::cin >> numEdges; nodes.resize(numNodes); for (int i = 0; i < numEdges; i++) { int a, b; std::cin >> a; std::cin >> b; a--; b--; nodes[a].connected.push_back(b); nodes[b].connected.push_back(a); } uint64_t x = 0; for (int i = 0; i < numNodes; i++) { nodes[i].visited = true; for (int c : nodes[i].connected) { x += count(c, false); } nodes[i].visited = false; } std::cout << x << std::endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...