제출 #1044129

#제출 시각아이디문제언어결과실행 시간메모리
1044129guagua0407Jobs (BOI24_jobs)C++17
100 / 100
208 ms71252 KiB
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int dx[4]={0,0,1,-1}; int dy[4]={1,-1,0,0}; void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } const int mxn=3e5+5; vector<int> adj[mxn]; vector<ll> x(mxn); vector<int> p(mxn); priority_queue<pair<ll,ll>> pq[mxn]; void dfs(int v){ for(auto u:adj[v]){ dfs(u); if(pq[u].size()>pq[v].size()) swap(pq[u],pq[v]); while(!pq[u].empty()){ pq[v].push(pq[u].top()); pq[u].pop(); } } pair<ll,ll> cur={min(0ll,x[v]),x[v]}; while(!pq[v].empty() and cur.s<=0){ cur.f=min(cur.f,cur.s+pq[v].top().f); cur.s+=pq[v].top().s; pq[v].pop(); } while(!pq[v].empty() and cur.f<=cur.s+pq[v].top().f){ cur.f=min(cur.f,cur.s+pq[v].top().f); cur.s+=pq[v].top().s; pq[v].pop(); } if(cur.s>0) pq[v].push(cur); } int main() {_ int n; cin>>n; cin>>x[0]; for(int i=1;i<=n;i++){ cin>>x[i]; int p; cin>>p; adj[p].push_back(i); } dfs(0); cout<<pq[0].top().s-x[0]<<'\n'; return 0; } //maybe its multiset not set //yeeorz //laborz

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

Main.cpp: In function 'void setIO(std::string)':
Main.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     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...
#Verdict Execution timeMemoryGrader output
Fetching results...