제출 #715325

#제출 시각아이디문제언어결과실행 시간메모리
715325lam통행료 (IOI18_highway)C++14
5 / 100
152 ms12888 KiB
#include "highway.h" #include <bits/stdc++.h> #define ll long long using namespace std; const int maxn = 2e5 + 10; typedef pair<int,int> ii; #define ff first #define ss second int n,m; ll dist,w1,w2,dist2; vector <ii> adj[maxn]; ii e[maxn]; int d[maxn]; ii par[maxn]; int side[maxn]; int dnc() { int l=0; int r=m-1; while (l<r) { int mid=(l+r)/2; vector <int> dau(m,0); for (int i=0; i<=mid; i++) dau[i] = 1; int temp = ask(dau); if (temp > dist) r = mid; else l=mid+1; } return r; } int trace(int lx, int rx, vector <int>&nodes, vector <int32_t> &dau) { if (lx==rx) return nodes[lx]; int mid=(lx+rx)/2; for (int i=lx; i<=mid; i++) dau[par[nodes[i]].ss] = 1; bool check = (ask(dau) > dist); for (int i=lx; i<=mid; i++) dau[par[nodes[i]].ss] = 0; if (check) return trace(lx,mid,nodes,dau); else return trace(mid+1,rx,nodes,dau); } void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) { m=U.size(); n=N; w1=A; w2=B; fill_n(side,n,0); for (int i=0; i<n; i++) par[i]={-1,-1}; cerr<<":>"<<endl; for (int i=0; i<n; i++) adj[i].clear(); for (int i=0; i<m; i++) e[i].ff=U[i], e[i].ss = V[i], adj[e[i].ff].push_back({e[i].ss,i}), adj[e[i].ss].push_back({e[i].ff,i}); vector <int32_t> dau(m,0); dist=ask(dau); dist2=ask(dau); cerr<<dist<<endl; int idx = dnc(); cerr<<idx<<endl; fill_n(d,n,-1); int u=e[idx].ff; int v=e[idx].ss; d[u]=d[v]=0; par[u] = par[v] = {-1,-1}; dau[idx] = -1; queue<int> q; q.push(u); q.push(v); side[u] = 1; side[v] = 2; while (!q.empty()) { int u=q.front(); q.pop(); for (ii i:adj[u]) { int v=i.ff; int id = i.ss; if (d[v]==-1) { par[v] = {u,id}; side[v] = side[u]; d[v] = d[u]+1; // cerr<<u<<" - "<<v<<endl; dau[id] = side[v]; q.push(v); } } } vector <int32_t> tmp(m,0); for (int i=0; i<m; i++) if (dau[i]==0) tmp[i]=1; for (int i=0; i<m; i++) if (dau[i]==1) tmp[i]=1; // for (int i:tmp) cerr<<i<<' '; cerr<<endl;cerr<<" = "<<ask(tmp)<<' '<<dist<<endl; ll du = 1LL*(ask(tmp)-dist)/(w2-w1); for (int i=0; i<m; i++) if (dau[i]==1) tmp[i]=0; for (int i=0; i<m; i++) if (dau[i]==2) tmp[i]=1; ll dv = 1LL*(ask(tmp)-dist)/(w2-w1); for (int i=0; i<m; i++) if (dau[i]==2) tmp[i]=0; // cerr<<u<<' '<<du<<" & "<<v<<' '<<dv<<endl; vector <int> nodes; for (int i=0; i<n; i++) if (side[i]==1&&d[i]==du) nodes.push_back(i); // for (int i=0; i<n; i++) cerr<<d[i]<<','<<side[i]<<' '; cerr<<endl; int s,t; // cerr<<nodes.size()<<endl; if (du==0) s=u; else s=trace(0,nodes.size()-1,nodes,tmp); nodes.clear(); for (int i=0; i<n; i++) if (side[i]==2&&d[i]==dv) nodes.push_back(i); if (dv==0) t=v; else t=trace(0,nodes.size()-1,nodes,tmp); 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...