社区讨论
样例过了,但全wa,求调
P1113杂务参与者 3已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @m1lktxo8
- 此快照首次捕获于
- 2024/09/28 11:12 去年
- 此快照最后确认于
- 2025/11/04 18:37 4 个月前
CPP
#include <bits/stdc++.h>
using namespace std;
int n,l[10010],d[10010];
vector<int> a[10010];
struct point{int x;int step;};
queue<point>q;
int ans = 0;
void out(){
for (int i = 1;i<=n;i++){
cout<<i<<"->";
for (int j = 0;j<a[i].size();j++) cout<<a[i][j]<<" ";
cout<<endl;
}
return;
}
int main(){
cin>>n;
for (int i = 1;i<=n;i++){
int p,c;cin>>p;cin>>l[p];
while(cin>>c && c!=0) a[c].push_back(p),d[p]++;
}
// out();
for (int i = 1;i<=n;i++) if (d[i]==0) q.push({i,1});
int ml = 0,sp = 1;
while(!q.empty()){
point now= q.front();q.pop();
// cout<<now.x<<":"<<now.step<<":"<<l[now.x]<<"->"<<endl;
if (now.step!=sp) ans+=ml,sp=now.step,ml=0;
ml = max(ml,l[now.x]);
for (int i = 0;i<a[now.x].size();i++){
int ee = a[now.x][i];
// cout<<ee;
if (--d[ee] == 0) q.push({ee,now.step+1});
}
// cout<<ml<<endl;
}
ans+=ml;
cout<<ans;
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...