제출 #1291833

#제출 시각아이디문제언어결과실행 시간메모리
1291833sitingfakeValley (BOI19_valley)C++20
100 / 100
133 ms37928 KiB
#include<bits/stdc++.h> using namespace std; // define #define execute cerr << " Time: " << fixed << setprecision(6) << (1.0 * clock() / CLOCKS_PER_SEC) << "s\n"; #define ll long long #define ii pair <int , int> #define iii pair <int , ii> #define se second #define fi first #define all(v) (v).begin() , (v).end() #define Unique(v) sort(all(v)) , v.resize(unique(all(v)) - v.begin()) #define bit(x,i) (((x) >> (i)) & 1LL) #define flip(x,i) ((x) ^ (1LL << (i))) #define ms(d,x) memset(d , x , sizeof(d)) #define exist __exist #define ends __ends #define visit visited #define left __left #define right __right #define prev __prev #define next __next #define sitingfake 1 #define orz 1 //constant const long long mod = 1e9 + 7; const long long linf = 4557430888798830399LL; const long long nlinf = -4485090715960753727LL; const int inf = 1061109567; const int ninf = -1044266559; const int dx[] = {0 , -1 , 0 , 1}; const int dy[] = {-1 , 0 , 1 , 0}; template<typename T> bool maximize(T &a, const T &b) { if(a < b) {a = b; return 1;} return 0; } template<typename T> bool minimize(T &a, const T &b) { if(a > b) {a = b; return 1;} return 0; } void Plus(ll & a ,ll b) { b %= mod; a += b; if(a < 0) a += mod; a %= mod; return; } void Mul(ll & a, ll b) { (a *= (b % mod)) %= mod; return; } //code const int maxn = 1e5 + 7; int n , q; vector <ii> adj[maxn]; int root , numshops; int depth[maxn] , in[maxn] , out[maxn] , par[maxn][20] , timer; ll mi[maxn][20] , val[maxn]; ii edges[maxn]; bool isShop[maxn]; ll dfs(int u , int p) { in[u] = ++timer; ll cur = linf; if(isShop[u]) cur = val[u]; for(ii i : adj[u]) { int v = i.fi; ll w = i.se; if(v != p) { depth[v] = depth[u] + 1; val[v] = val[u] + w; par[v][0] = u; cur = min(cur , dfs(v , u)); } } if(cur != linf) mi[u][0] = cur - 2 * val[u]; out[u] = timer; return cur; } void BuildLca() { for(int j = 1; (1 << j) <= n; j++) { for(int i = 1; i <= n; i++) { par[i][j] = par[par[i][j - 1]][j - 1]; mi[i][j] = min(mi[i][j - 1] , mi[par[i][j - 1]][j - 1]); } } } ll Jump(int d , int u) { int cur = u; ll ans = linf; for(int i = 0; (1 << i) <= d; i++) { if(bit(d , i)) { ans = min(ans , mi[cur][i]); cur = par[cur][i]; } } return min(ans , mi[cur][0]); } void solve(void) { cin >> n >> numshops >> q >> root; for(int i = 1; i < n; i++) { int u , v , w; cin >> u >> v >> w; adj[u].push_back({v , w}); adj[v].push_back({u , w}); edges[i] = ii(u , v); } for(int i = 1; i <= numshops; i++) { int u; cin >> u; isShop[u] = 1; } ms(mi , 0x3f); dfs(root , -1); BuildLca(); while(q--) { int id , u; cin >> id >> u; int p; if(depth[edges[id].fi] > depth[edges[id].se]) { p = edges[id].fi; } else { p = edges[id].se; } if(in[p] <= in[u] && out[u] <= out[p]) { ll tmp = Jump(depth[u] - depth[p] , u); if(tmp == linf) { cout << "oo\n"; } else { cout << tmp + val[u] << "\n"; } } else cout << "escaped\n"; } } /** **/ signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "" if(fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } int tc = 1; // cin >> tc; while(tc--) solve(); // execute; }

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

valley.cpp: In function 'int main()':
valley.cpp:192:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  192 |        freopen(task".inp","r",stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
valley.cpp:193:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  193 |        freopen(task".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...