제출 #741543

#제출 시각아이디문제언어결과실행 시간메모리
741543myrcella통행료 (IOI18_highway)C++17
5 / 100
122 ms7788 KiB
//by szh #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pii pair<int,int> #define pll pair<long long,long long> #define pb push_back #define debug(x) cerr<<#x<<"="<<x<<endl #define pq priority_queue #define inf 0x3f #define rep(i,a,b) for (int i=a;i<(b);i++) #define MP make_pair #define SZ(x) (int(x.size())) #define ll long long #define mod 1000000007 #define ALL(x) x.begin(),x.end() void inc(int &a,int b) {a=(a+b)%mod;} void dec(int &a,int b) {a=(a-b+mod)%mod;} int lowbit(int x) {return x&(-x);} ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;} #include "highway.h" const int maxn = 9e4+10; int fa[maxn]; bool mark[maxn]; bool ans[maxn]; vector <int> ww; vector <pii> edge[maxn]; int dis,dif; int ret[maxn]; void solve(vector <int> tmp,int cnt) { if (SZ(tmp)==1) { ans[tmp[0]] = 1; return; } vector <int> left; int mid = SZ(tmp)/2; rep(i,0,mid) ww[tmp[i]] = 1,left.pb(tmp[i]); int diss = ask(ww); rep(i,0,mid) ww[tmp[i]] = 0; vector <int> right; rep(i,mid,SZ(tmp)) right.pb(tmp[i]); if (diss>dis) solve(left,(diss-dis)/dif); if ((diss-dis)/dif<cnt) solve(right,cnt-(diss-dis)/dif); } bool dfs(int u,int lst,int rest) { if (rest==0) return true; vector <int> tmp; fa[u] = lst; int cnt = 0; for (pii v:edge[u]) { if (v.fi==lst) continue; tmp.pb(v.se); cnt++; } assert(cnt!=0); if (cnt==1) { for (pii v:edge[u]) { if (v.fi==lst) continue; dfs(v.fi,u,rest-1); ans[v.se] = 1; } return true; } solve(tmp,1); for (pii v:edge[u]) if (v.fi!=lst and ans[v.se]==1) return dfs(v.fi,u,rest-1); } void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) { rep(i,0,N-1) { edge[U[i]].pb({V[i],i}); edge[V[i]].pb({U[i],i}); } rep(i,1,N) ww.pb(0); dis = ask(ww); dif = B-A; dfs(0,-1,dis/A); rep(i,0,N-1) if (ans[i]) ret[U[i]]++,ret[V[i]]++; int u=-1,v=-1; rep(i,0,N) if (ret[i]==1) { if (u==-1) u = i; else v = i; } answer(u,v); }

컴파일 시 표준 에러 (stderr) 메시지

highway.cpp: In function 'bool dfs(int, int, int)':
highway.cpp:54:15: warning: control reaches end of non-void function [-Wreturn-type]
   54 |  vector <int> tmp;
      |               ^~~
#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...