Submission #979800

#TimeUsernameProblemLanguageResultExecution timeMemory
979800MarcusSwapping Cities (APIO20_swap)C++17
6 / 100
89 ms16060 KiB
#include <swap.h> #include <bits/stdc++.h> using namespace std; int n, m; vector<vector<pair<int, int>>> adj; vector<bool> visited; bool cycle = false; int gas = 0; void dfs(int s, int v) { if (visited[s]) return; visited[s] = true; for (auto u: adj[s]) { if (visited[u.first] && u.first != v) cycle = true; gas = max(gas, u.second); dfs(u.first, s); } } namespace subtask2 { bool nodes = false; bool variation = false; bool execution = false; vector<pair<int, int>> edge; } void init(int n1, int m1, vector<int> v, vector<int> u, vector<int> w) { n = n1; m = m1; adj.resize(n); visited.resize(n); for (int i=0; i<m; i++) { adj[v[i]].push_back({u[i], w[i]}); adj[u[i]].push_back({v[i], w[i]}); } //confirmation for subtask2 if (m == (n-1)) {subtask2::nodes = true;} for (auto s: v) {if (s != 0) {subtask2::variation = true;}} subtask2::execution = (subtask2::nodes && !(subtask2::variation)); if (subtask2::execution) { for (auto u: adj[0]) { subtask2::edge.push_back({u.second, u.first}); } sort(subtask2::edge.begin(), subtask2::edge.end()); subtask2::edge.erase(subtask2::edge.begin()+3, subtask2::edge.end()); } } int getMinimumFuelCapacity(int x, int y){ if (subtask2::execution) { if (n < 4) return -1; gas = max(adj[x][0].second, adj[y][0].second); for (auto &u: subtask2::edge) { if (u.second != x && u.second != y) {return max(u.first, gas);} } } dfs(1, 0); return (cycle ? gas : -1); }
#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...