Submission #478102

# Submission time Handle Problem Language Result Execution time Memory
478102 2021-10-05T15:06:35 Z starplat Islands (IOI08_islands) C++14
24 / 100
1769 ms 131072 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,v,w,vis[1000005],dist[1000005],path,ans;
vector<pair<int,int>> g[1000005];
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 (vis[i.first]) continue;
			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;
			}
			//cout<<node<<" "<<mx<<"\n";
			path=0;
			dij(node);
			for (int i:clr) path=max(path,dist[i]);
			clr.clear();
			ans+=path;
			//cout<<path<<"\n";
		}
	}
	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
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 12 ms 23820 KB Output is correct
3 Incorrect 12 ms 23756 KB Output isn't correct
4 Correct 12 ms 23728 KB Output is correct
5 Correct 16 ms 23756 KB Output is correct
6 Correct 12 ms 23668 KB Output is correct
7 Incorrect 16 ms 23756 KB Output isn't correct
8 Incorrect 17 ms 23772 KB Output isn't correct
9 Correct 13 ms 23756 KB Output is correct
10 Correct 14 ms 23756 KB Output is correct
11 Correct 11 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 23884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 23936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 24908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 82 ms 28648 KB Output is correct
2 Incorrect 108 ms 32084 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 221 ms 43848 KB Output is correct
2 Correct 211 ms 42552 KB Output is correct
3 Incorrect 292 ms 50508 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 394 ms 53820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1769 ms 131072 KB Output is correct
2 Incorrect 1723 ms 131072 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 903 ms 118024 KB Output is correct
2 Correct 921 ms 118432 KB Output is correct
3 Incorrect 917 ms 118524 KB Output isn't correct
4 Halted 0 ms 0 KB -