답안 #1062404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1062404 2024-08-17T06:14:25 Z tamir1 Islands (IOI08_islands) C++17
24 / 100
207 ms 131072 KB
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
using namespace std;
int n,x,p;
vector<pair<int,ll>> v[1000002];
vector<int> com[1000001];
ll ans,l,dis[1000001];
bitset<1000001> ok;
priority_queue<pair<ll,int>> q;
void dfs(int x){
	if(ok[x]) return;
	ok[x]=1;
	com[p].push_back(x);
	for(pair<int,ll> i:v[x]){
		dfs(i.ff);
	}
}
void dijk(){
	while(!q.empty()){
		ll d=q.top().ff;
		int x=q.top().ss;
		q.pop();
		if(ok[x]) continue;
		ok[x]=1;
		dis[x]=d;
		for(pair<int,ll> i:v[x]){
			if(!ok[i.ff]) q.push({d+i.ss,i.ff});
		}
	}
}
ll solve(int p){
	q.push({0,com[p][0]});
	dijk();
	ll mx=0;
	int x;
	for(int i:com[p]){
		if(mx<dis[i]){
			x=i;
			mx=dis[i];
		}
		dis[i]=0;
		ok[i]=0;
	}
	q.push({0,x});
	dijk();
	mx=0;
	for(int i:com[p]){
		mx=max(dis[i],mx);
	}
	//cout << mx << "\n";
	return mx;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> x >> l;
		v[i].push_back({x,l});
		v[x].push_back({i,l});
	}
	for(int i=1;i<=n;i++){
		if(!ok[i]){
			p++;
			dfs(i);
		}
	}
	ok.reset();
	for(int i=1;i<=p;i++) ans+=solve(i);
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 48984 KB Output is correct
2 Correct 8 ms 48988 KB Output is correct
3 Incorrect 8 ms 49112 KB Output isn't correct
4 Correct 8 ms 49040 KB Output is correct
5 Correct 8 ms 48984 KB Output is correct
6 Correct 8 ms 49008 KB Output is correct
7 Incorrect 8 ms 49032 KB Output isn't correct
8 Incorrect 8 ms 48984 KB Output isn't correct
9 Correct 7 ms 49240 KB Output is correct
10 Correct 8 ms 48988 KB Output is correct
11 Correct 8 ms 49184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 49240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 49120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 52316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 55928 KB Output is correct
2 Incorrect 36 ms 58972 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 66244 KB Output is correct
2 Correct 71 ms 68944 KB Output is correct
3 Incorrect 109 ms 78484 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 127 ms 81464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 201 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 207 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -