제출 #719737

#제출 시각아이디문제언어결과실행 시간메모리
719737bin9638통행료 (IOI18_highway)C++17
51 / 100
235 ms262144 KiB
#include <bits/stdc++.h> #ifndef SKY #include "highway.h" #endif // SKY using namespace std; #define N 200010 #define ll long long #define fs first #define sc second #define ii pair<int,int> #define pb push_back int times,cha[N][21],n,m,depth[N],par_id[N]; ll A,B; ii canh[N],cnt[N]; vector<ii>g[N]; #ifdef SKY int S_ans,T_ans; void answer(int s,int t) { cout<<s<<" "<<t<<endl; } ll dis[55][55]; ll ask(vector<int>w) { memset(dis,0x3f3f,sizeof(dis)); for(int i=0;i<m;i++) dis[canh[i].fs][canh[i].sc]=dis[canh[i].sc][canh[i].fs]=(w[i]==0 ? A : B); for(int k=0;k<n;k++) for(int i=0;i<n;i++) for(int j=0;j<n;j++) dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]); return dis[S_ans][T_ans]; } #endif // SKY ll my_ask(vector<int>w) { return ask(w); } ll get(vector<int>s) { vector<int>w(m,0); for(auto u:s) w[par_id[u]]=1; return my_ask(w); } void DFS(int u,int p) { cnt[u].fs=++times; for(auto v:g[u]) if(v.fs!=p) { par_id[v.fs]=v.sc; depth[v.fs]=depth[u]+1; cha[v.fs][0]=u; DFS(v.fs,u); } cnt[u].sc=times; } bool tren(int u,int v) { return (cnt[u].fs<=cnt[v].fs&&cnt[u].sc>=cnt[v].sc); } void find_pair(int cc, vector<int> canh_fs, vector<int> canh_sc, int AAA, int BBB) { n=cc; m=canh_fs.size(); A=AAA; B=BBB; for(int i=0;i<m;i++) { canh[i]={canh_fs[i],canh_sc[i]}; g[canh[i].fs].pb({canh[i].sc,i}); g[canh[i].sc].pb({canh[i].fs,i}); } vector<int>s(m,0); ll val=my_ask(s); memset(par_id,-1,sizeof(par_id)); DFS(0,-1); int sau=-1,l=1,r=*max_element(depth,depth+n); while(l<=r) { int mid=(l+r)/2; vector<int>hoi(n-1,1); for(int i=1;i<n;i++) if(depth[i]<mid) hoi[par_id[i]]=0; if(val!=my_ask(hoi)) { sau=mid; l=mid+1; }else r=mid-1; } s.clear(); for(int i=1;i<n;i++) if(depth[i]==sau) s.pb(i); //cout<<s.size()<<endl; while(s.size()>1) { vector<int>L,R; for(int i=0;i<s.size();i++) if(i*2<s.size()) L.pb(s[i]); else R.pb(s[i]); if(get(L)!=val) s=L; else s=R; } int u=s[0],lca=u; { vector<int>hoi(m,0); int p=u; while(p!=0) { hoi[par_id[p]]=1; p=cha[p][0]; } for(int i=(my_ask(hoi)-val)/(B-A);i>=1;i--) lca=cha[lca][0]; } sau=depth[lca]+((my_ask(vector<int>(m,1))-val)/(B-A)-(depth[u]-depth[lca])); // cout<<u<<" "<<lca<<" "<<sau<<endl; if(sau==depth[lca]) { answer(u,lca); return; } s.clear(); for(int i=0;i<n;i++) if(depth[i]==sau&&!tren(i,u)) s.pb(i); while(s.size()>1) { vector<int>L,R; for(int i=0;i<s.size();i++) if(i*2<s.size()) L.pb(s[i]); else R.pb(s[i]); if(get(L)!=val) s=L; else s=R; } answer(s[0],u); } #ifdef SKY int main() { freopen("A.inp","r",stdin); freopen("A.out","w",stdout); ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n,m,A,B; cin>>n>>m>>S_ans>>T_ans>>A>>B; vector<int>u(m),v(m); for(int i=0;i<m;i++) cin>>u[i]>>v[i]; find_pair(n,u,v,A,B); return 0; } #endif

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

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:115:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |         for(int i=0;i<s.size();i++)
      |                     ~^~~~~~~~~
highway.cpp:116:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |             if(i*2<s.size())
      |                ~~~^~~~~~~~~
highway.cpp:149:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  149 |         for(int i=0;i<s.size();i++)
      |                     ~^~~~~~~~~
highway.cpp:150:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  150 |             if(i*2<s.size())
      |                ~~~^~~~~~~~~
#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...