Submission #1087103

#TimeUsernameProblemLanguageResultExecution timeMemory
1087103PieArmyValley (BOI19_valley)C++17
23 / 100
180 ms68948 KiB
typedef long long ll; ll pie(ll army){return (1ll<<army);} #include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define endl '\n' #define mid ((left+right)>>1) const ll inf=2000000000000000005; const int sonsuz=2000000005; using namespace std; ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;} #define int ll int n,s,q,root; int dep[100001],par[100001][20]; ll dis[100001][20],res[100001][20]; ll bes[100001]; int shop[100001]; vector<pair<int,pair<int,int>>>komsu[100001]; int subroot[100001]; void dfs(int pos){ for(int i=1;i<20;i++){ par[pos][i]=par[par[pos][i-1]][i-1]; dis[pos][i]=dis[pos][i-1]+dis[par[pos][i-1]][i-1]; } if(shop[pos])bes[pos]=0; for(pair<int,pair<int,int>>x:komsu[pos]){ if(x.fr==par[pos][0]){ subroot[x.sc.sc]=pos; continue; } par[x.fr][0]=pos; dis[x.fr][0]=x.sc.fr; dep[x.fr]=dep[pos]+1; dfs(x.fr); bes[pos]=min(bes[pos],bes[x.fr]+x.sc.fr); } } void code(){ cin>>n>>s>>q>>root; for(int i=1;i<=n;i++){ bes[i]=inf; } for(int i=1;i<n;i++){ int x,y,w; cin>>x>>y>>w; komsu[x].pb({y,{w,i}}); komsu[y].pb({x,{w,i}}); } par[root][0]=root; for(int i=1;i<=s;i++){ int x;cin>>x; shop[x]=1; } dfs(root); for(int i=1;i<=n;i++){ res[i][0]=min(bes[i],bes[par[i][0]]+dis[i][0]); } for(int i=1;i<20;i++){ for(int j=1;j<=n;j++){ res[j][i]=min(res[j][i-1],res[par[j][i-1]][i-1]+dis[j][i-1]); } } while(q--){ int a,b;cin>>b>>a; b=subroot[b]; ll ans=bes[a]; if(dep[b]>dep[a]){ cout<<"escaped\n"; continue; } for(int i=0;i<20;i++){ if((dep[a]-dep[b])&pie(i)){ ans=min(ans,res[a][i]); a=par[a][i]; } } if(a!=b){ cout<<"escaped\n"; continue; } if(ans==inf){ cout<<"oo\n"; continue; } cout<<ans<<endl; } } int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);} int t=1; if(!t)cin>>t; while(t--){code();cout<<endl;} return 0; }

Compilation message (stderr)

valley.cpp: In function 'int32_t main()':
valley.cpp:94:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |  bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~
valley.cpp:94:57: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |  bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
      |                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...