제출 #979796

#제출 시각아이디문제언어결과실행 시간메모리
979796Marcus자매 도시 (APIO20_swap)C++17
6 / 100
86 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+1); visited.resize(n+1); 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 (m1 == (n1-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...