제출 #292873

#제출 시각아이디문제언어결과실행 시간메모리
292873Atill83통행료 (IOI18_highway)C++14
12 / 100
309 ms262148 KiB
#include "highway.h" #include <bits/stdc++.h> #define ff first #define ss second using namespace std; typedef pair<int, int> pii; vector<int> sor; vector<int> cnd; const int MAXN = (int) 9e4 + 5; vector<pii> adj[MAXN]; int open[MAXN]; int dep[MAXN]; long long der; void dfs(int v, int par){ if(dep[v] == der) {cnd.push_back(v); return;} for(pii u: adj[v]){ int j = u.ff; if(j != par){ dep[j] = dep[v] + 1; dfs(j, v); } } } bool dfs1(int v, int par){ if(open[v]) return 1; bool vardi = 0; for(pii u: adj[v]){ if(u.ff == par) continue; bool var = dfs1(u.ff, v); vardi |= var; if(var){ sor[u.ss] = 0; } } return vardi; } void find_pair(int N, vector<int> U, vector<int> V, int A, int B) { int M = U.size(); int s = 0, t; for(int i = 0; i < M; i++) { sor.push_back(0); adj[U[i]].push_back({V[i], i}); adj[V[i]].push_back({U[i], i}); } der = ask(sor) / A; dfs(0, -1); int l = 0, r = cnd.size() - 1; while(l < r){ int m = (l + r) / 2; for(int i = 0; i < M; i++) sor[i] = 1; for(int i = l; i <= m; i++){ open[cnd[i]] = 1; } dfs1(0, -1); for(int i = l; i <= m; i++){ open[cnd[i]] = 0; } long long dr = ask(sor); if(dr == der*A){ r = m; }else{ l = m + 1; } } t = cnd[l]; answer(s,t); }
#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...