이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//
// Created by adavy on 8/18/2024.
//
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//#define int ll
#define f first
#define s second
/*
pair<ll,ll> merge(pair<ll,ll> a, pair<ll,ll> b){
return {min(a.f,b.f),a.s-max(a.f,b.f)+b.s};
}
struct prs{
set<pair<ll,ll>> ps;
void insert(pair<ll,ll> p){
cout << "ps: " << endl;
for(auto& itm:ps){
cout << itm.f << " " << itm.s << endl;
}
cout << "p: " << p.f << " " << p.s << endl;
while(1){
auto it = ps.lower_bound(p);
if (it != ps.end()) {
if (it-> f <= p.s){
p = merge(p,*it);
ps.erase(it);
continue;
}
}
auto it2 = ps.upper_bound(p);
if (it2 != ps.begin()){
--it2;
if (it2->s >= p.f){
p = merge(p,*it2);
ps.erase(it2);
continue;
}
}
if (p.f > p.s){
ps.clear();
return;
}
ps.insert(p);
break;
}
}
void subtract(ll x){
ll balance = -x;
ll neg = balance;
while (!ps.empty() && balance < 0){
balance -= ps.begin()->f;
neg = min(neg,balance);
balance += ps.begin()->s;
ps.erase(ps.begin());
}
if (balance >= 0){
this->insert({-neg,balance-neg});
}
}
};
vector<int> val;
vector<prs> sets;
vector<int> which;
*/
vector<vector<int>> adj;
void dfs(int v, int p){
cout << "v: " << v << endl;
//int maxsz = -1, maxch = -1;
for(int u:adj[v]){
if (u == p) continue;
/*
cout << "Foo" << endl;
cout << "u: " << u << endl;*/
dfs(u,v);
/*
if (sets[u].ps.size() > maxsz){
maxsz = sets[u].ps.size();
maxch = u;
}*/
}
/*
if (maxsz == -1){
which[v] = v;
}
else {
which[v] = which[maxch];
}
for(int u:adj[v]){
if (u==p || u == maxch) continue;
for(auto& itm:sets[u].ps){
sets[which[v]].insert(itm);
}
}
if (val[v] > 0){
sets[which[v]].insert({0LL,val[v]});
}
else {
sets[which[v]].subtract(-val[v]);
}
// output v, sets[which[v]].ps
cout << "v: " << v << endl;
for(auto& itm:sets[which[v]].ps){
cout << itm.f << " " << itm.s << endl;
}*/
}
signed main(){
freopen("input.txt","r",stdin);
std::ios::sync_with_stdio(false); cin.tie(NULL);
int N,s; cin >> N >> s;
adj.resize(N+5);
//val.resize(N+1);
//sets.resize(N+1);
//which.resize(N+1,-1);
//val[0] = 0;
for(int i=1;i<=N;++i){
ll x,p; cin >> x >> p;
//val[i] = x;
adj[p].push_back(i);
adj[i].push_back(p);
}
dfs(0,-1);
//int t = s;
/*
for(auto& item:sets[which[0]].ps){
if (t >= item.f){
t -= item.f;
t += item.s;
}
}*/
//cout << t-s << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:135:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
135 | freopen("input.txt","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |