#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define int long long
const long long inf=1e18;
const int MOD=1e9+7;
const int N=1e6+1;
vector<pair<int,int>> adj[N];
int low[N],sum=0,mn=inf,ans=0;
map<pair<int,int>,int> mp;
void dfs(int node,int depth,int par){
low[node]=depth;
for(auto i:adj[node]){
if(i.first==par)continue;
if(low[i.first]==0){
dfs(i.first,depth+1,node);
sum+=mp[{min(i.first,node),max(i.first,node)}];
if(low[i.first]<low[node])mn=min(mn,mp[{min(i.first,node),max(i.first,node)}]);
low[node]=min(low[node],low[i.first]);
}
else{
low[node]=min(low[node],low[i.first]);
}
}
}
signed main()
{
int n; cin>>n;
for(int i=1;i<=n;i++){
int x,l; cin>>x>>l;
mp[{min(i,x),max(i,x)}]=l;
}
for(auto i:mp){
adj[i.first.first].pb({i.first.second,i.second});
adj[i.first.second].pb({i.first.first,i.second});
}
for(int i=1;i<=n;i++){
if(low[i]==0){
dfs(i,1,0);
if(mn==inf)mn=0;
ans+=sum-mn;
sum=0; mn=inf;
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
23900 KB |
Output isn't correct |
2 |
Incorrect |
10 ms |
23896 KB |
Output isn't correct |
3 |
Incorrect |
9 ms |
23896 KB |
Output isn't correct |
4 |
Correct |
8 ms |
23900 KB |
Output is correct |
5 |
Incorrect |
9 ms |
25176 KB |
Output isn't correct |
6 |
Incorrect |
9 ms |
25180 KB |
Output isn't correct |
7 |
Incorrect |
9 ms |
25436 KB |
Output isn't correct |
8 |
Incorrect |
9 ms |
25432 KB |
Output isn't correct |
9 |
Incorrect |
8 ms |
25436 KB |
Output isn't correct |
10 |
Incorrect |
9 ms |
25436 KB |
Output isn't correct |
11 |
Incorrect |
9 ms |
25432 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
25436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
25432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
27740 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
50 ms |
34900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
135 ms |
54864 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
274 ms |
81276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
589 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
598 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |