QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#483686 | #410. Telegraph | Rafi22 | 0 | 1ms | 7776kb | C++20 | 1.9kb | 2024-07-19 04:58:19 | 2024-07-19 04:58:20 |
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif
#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define ROF(i,r,l) for(int i=(r);i>=(l);i--)
int inf=1000000007;
ll infl=1000000000000000007;
ll mod=1000000007;
ll mod1=998244353;
const int N=100007;
bool is[N];
int a[N];
ll c[N];
ll DP[N];
int ile[N];
bool odw[N];
vector<int>G[N];
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
ll sum=0,ans=0;
FOR(i,1,n)
{
cin>>a[i]>>c[i];
ile[a[i]]++;
sum+=c[i];
G[a[i]].pb(i);
}
deque<int>Q;
FOR(i,1,n) if(ile[i]==0) Q.pb(i);
while(sz(Q)>0)
{
int v=Q[0];
Q.pop_front();
odw[v]=1;
is[v]=1;
ll mx=0;
for(auto u:G[v])
{
DP[v]+=DP[u];
mx=max(mx,c[u]);
}
DP[v]+=mx;
ile[a[v]]--;
if(ile[a[v]]==0) Q.pb(a[v]);
}
FOR(i,1,n)
{
if(odw[i]) continue;
vector<int>V;
int x=i;
ll S=0;
while(!odw[x])
{
odw[x]=1;
S+=c[x];
for(auto u:G[x]) S+=DP[u];
V.pb(x);
x=a[x];
}
debug(V);
debug(S);
ll mx=0;
if(sz(V)==n) mx=S;
FOR(j,0,sz(V)-1)
{
ll xd=0;
for(auto u:G[V[j]]) if(is[u]) xd=max(xd,c[u]);
debug(xd);
//debug(S+xd-c[V[(j-1+sz(V))%sz(V)]]);
mx=max(mx,S+xd-c[V[(j-1+sz(V))%sz(V)]]);
}
ans+=mx;
}
cout<<sum-ans<<endl;
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 0ms
memory: 5692kb
input:
10 3 85377744 3 191391530 4 553475509 8 344887257 9 812158120 1 880268352 4 686078706 7 182546394 4 220137367 3 89957933
output:
1081551750
result:
ok single line: '1081551750'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5936kb
input:
10 3 688989554 5 112566798 1 294281317 1 96941112 6 746415334 2 612836992 9 629868215 1 406822326 10 638640051 8 199983696
output:
503789227
result:
ok single line: '503789227'
Test #3:
score: 0
Accepted
time: 0ms
memory: 7776kb
input:
10 3 292601364 7 33742065 7 35087125 3 996478615 4 828156197 3 197921984 8 426174077 4 631098259 5 57142735 5 457493107
output:
1212506407
result:
ok single line: '1212506407'
Test #4:
score: 0
Accepted
time: 0ms
memory: 7632kb
input:
10 6 43696822 9 954917333 7 923376581 5 896016118 1 762413411 4 930490625 3 369963586 9 855374192 2 475645419 1 567518871
output:
1936096612
result:
ok single line: '1936096612'
Test #5:
score: -10
Wrong Answer
time: 0ms
memory: 7676kb
input:
10 6 647308632 3 876092601 4 664182389 6 648069973 7 844154274 5 663059265 1 166269448 3 79650124 7 894148102 7 825028282
output:
2396902653
result:
wrong answer 1st lines differ - expected: '2396141312', found: '2396902653'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%