QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#483685 | #410. Telegraph | Rafi22 | 0 | 0ms | 3652kb | C++20 | 1.7kb | 2024-07-19 04:47:57 | 2024-07-19 04:47:57 |
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;
int a[N];
ll c[N];
ll DP[N];
ll DP1[N];
int ile[N];
bool odw[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];
}
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;
DP[a[v]]=max(DP[a[v]],DP[v]+c[v]);
DP1[a[v]]=max(DP1[a[v]],DP[v]);
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]+DP1[x];
debug(DP1[x]);
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) mx=max(mx,S+DP[V[j]]-DP1[V[j]]-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: 0
Wrong Answer
time: 0ms
memory: 3652kb
input:
10 3 85377744 3 191391530 4 553475509 8 344887257 9 812158120 1 880268352 4 686078706 7 182546394 4 220137367 3 89957933
output:
1999723656
result:
wrong answer 1st lines differ - expected: '1081551750', found: '1999723656'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%