답안 #478096

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478096 2021-10-05T15:02:04 Z starplat Islands (IOI08_islands) C++14
0 / 100
145 ms 26708 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,v,w,vis[100005],dist[100005],path,ans;
vector<pair<int,int>> g[100005];
vector<int> clr;
priority_queue<pair<int,int>> q;
void dij(int x)
{
	q.push({0,x});
	while (q.size()){
		v=q.top().second;
		q.pop();
		if (vis[v]) continue;
		vis[v]=1;
		clr.push_back(v);
		for (auto i:g[v]){
			if (dist[i.first]<dist[v]+i.second){
				dist[i.first]=dist[v]+i.second;
				q.push({dist[i.first],i.first});
			}
		}
	}
}
signed main()
{
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>v>>w;
		g[i].push_back({v,w});
		g[v].push_back({i,w});
	}
	for (int i=1;i<=n;i++){
		if (!vis[i]) {
			dij(i);
			int mx=0,node=0;
			for (int i:clr) {
				if (dist[i]>mx) mx=dist[i],node=i;
				dist[i]=0,vis[i]=0;
			}
			path=0;
			dij(node);
			for (int i:clr) path=max(path,dist[i]);
			clr.clear();
			ans+=path;
		}
	}
	cout<<ans<<"\n";
}
//for each connected component find the tree diameter,and travel to next subgraph?
//dijstra with longest path?
//love to do graph questions, at the same time hate don't no how to solve graph questions
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2640 KB Output isn't correct
2 Incorrect 2 ms 2640 KB Output isn't correct
3 Incorrect 2 ms 2640 KB Output isn't correct
4 Incorrect 2 ms 2640 KB Output isn't correct
5 Incorrect 2 ms 2640 KB Output isn't correct
6 Incorrect 2 ms 2640 KB Output isn't correct
7 Incorrect 2 ms 2640 KB Output isn't correct
8 Incorrect 2 ms 2640 KB Output isn't correct
9 Incorrect 2 ms 2640 KB Output isn't correct
10 Incorrect 2 ms 2652 KB Output isn't correct
11 Incorrect 2 ms 2648 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 4124 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 71 ms 8208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 23 ms 8528 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 145 ms 26708 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 5200 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 21 ms 7632 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -