답안 #1008414

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1008414 2024-06-26T11:51:04 Z vjudge1 Islands (IOI08_islands) C++17
3 / 100
668 ms 131072 KB
#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;
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+=i.second;
            if(low[i.first]<low[node])mn=min(mn,i.second);
            low[node]=min(low[node],low[i.first]);
        }
        else{
            low[node]=min(low[node],low[i.first]);
        }
    }
}
signed main()
{
   int n; cin>>n;
    map<pair<int,int>,int> mp;
    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 8 ms 23896 KB Output isn't correct
2 Incorrect 9 ms 23896 KB Output isn't correct
3 Incorrect 9 ms 23916 KB Output isn't correct
4 Correct 9 ms 23900 KB Output is correct
5 Incorrect 10 ms 23900 KB Output isn't correct
6 Incorrect 10 ms 23900 KB Output isn't correct
7 Incorrect 8 ms 23704 KB Output isn't correct
8 Incorrect 9 ms 23900 KB Output isn't correct
9 Incorrect 8 ms 23900 KB Output isn't correct
10 Incorrect 9 ms 23900 KB Output isn't correct
11 Incorrect 8 ms 23792 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 25436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 25436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 27228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 43 ms 32836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 118 ms 51024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 245 ms 74932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 615 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 668 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -