Submission #945609

#TimeUsernameProblemLanguageResultExecution timeMemory
945609yeediotValley (BOI19_valley)C++14
0 / 100
108 ms48884 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define F first #define S second #define all(x) x.begin(),x.end() #define pii pair<int,int> #define pb push_back #define sz(x) (int)(x.size()) #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) #define vi vector<int> #define vp vector<pii> #define vvi vector<vi> #define ykh mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()) #define __lg(x) 63-__builtin_clzll(x) #define pow2(x) (1LL<<x) void __print(int x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifdef local void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);} #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else void setio(){} #define debug(x...) #endif void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } struct line{ int a,b; int operator()(const int x)const{ return a*x+b; } }; bool check(line l1,line l2,line l3){ return (l3.b-l2.b)*(l1.a-l2.a)<=(l2.b-l1.b)*(l2.a-l3.a); } const int mxn=1e5+5; vector<pii>adj[mxn]; bool isshop[mxn]; int dep[mxn],d[mxn]; int in[mxn],out[mxn]; int timer; vector<tuple<int,int,int>>edge; int jump[20][mxn],mn[20][mxn]; int ord[mxn]; int dp[mxn]; int pre[mxn]; void dfs(int v,int pa){ in[v]=++timer; ord[timer]=v; jump[0][v]=pa; if(isshop[v])dp[v]=0; else dp[v]=1e18; for(auto [u,pp]:adj[v]){ if(u==pa)continue; dep[u]=dep[v]+pp; d[u]=d[v]+1; dfs(u,v); dp[v]=min(dp[v],dp[u]+pp); } out[v]=timer; } int lca(int v,int u){ if(dep[v]<dep[u])swap(v,u); int dif=d[v]-d[u]; for(int i=0;i<20;i++){ if(dif>>i&1){ v=jump[i][v]; } } if(v==u)return v; for(int i=19;i>=0;i--){ if(jump[i][v]!=jump[i][u]){ v=jump[i][v]; u=jump[i][u]; } } return jump[0][v]; } int ans[mxn]; void calc(int v,int pa){ mn[0][v]=dp[jump[0][v]]-dep[jump[0][v]]; for(auto [u,dd]:adj[v]){ if(u==pa)continue; calc(u,v); } } signed main(){ setio(); ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); int n,s,q,e; cin>>n>>s>>q>>e; for(int i=1;i<n;i++){ int a,b,c; cin>>a>>b>>c; adj[a].pb({b,c}); adj[b].pb({a,c}); edge.pb({a,b,c}); } for(int i=1;i<=s;i++){ int x; cin>>x; isshop[x]=1; } dfs(e,e); for(int i=1;i<20;i++){ for(int j=1;j<=n;j++){ jump[i][j]=jump[i-1][jump[i-1][j]]; } } calc(e,e); for(int i=1;i<=n;i++){ debug(mn[0][i],jump[0][i],dp[i],dep[i]); } for(int i=1;i<20;i++){ for(int j=1;j<=n;j++){ mn[i][j]=min(mn[i-1][j],mn[i-1][jump[i-1][j]]); } } while(q--){ int id,v; cin>>id>>v; id--; auto [x,y,l]=edge[id]; if(d[x]<d[y])swap(x,y); debug(x); if(in[x]<=in[v] and in[v]<=out[x]){ int an=dp[v]+dep[v]; int cur=v; for(int i=19;i>=0;i--){ if(dep[jump[i][cur]]>=dep[x]){ an=min(an,mn[i][cur]+dep[v]); cur=jump[i][cur]; debug(cur); } } if(an>=1e18){ cout<<"oo\n"; } else{ cout<<an<<'\n'; } } else{ cout<<"escaped\n"; } } } /* input: */

Compilation message (stderr)

valley.cpp: In function 'void dfs(long long int, long long int)':
valley.cpp:71:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   71 |     for(auto [u,pp]:adj[v]){
      |              ^
valley.cpp: In function 'void calc(long long int, long long int)':
valley.cpp:100:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  100 |     for(auto [u,dd]:adj[v]){
      |              ^
valley.cpp: In function 'int main()':
valley.cpp:142:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  142 |         auto [x,y,l]=edge[id];
      |              ^
valley.cpp: In function 'void setIO(std::string)':
valley.cpp:42:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
valley.cpp:43:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     freopen((s + ".out").c_str(), "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...