Submission #997183

# Submission time Handle Problem Language Result Execution time Memory
997183 2024-06-11T19:33:29 Z codefox Dreaming (IOI13_dreaming) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>

vector<int> depth;
vector<vector<pii>> graph;
vector<int> vis;
vector<int> vis2;
vector<int> nums;

void dfs(int i, int d)
{
	if(vis[i]) return;
	vis[i] = 1;
	nums.push_back(i);
	depth[i] = d;
	for (pii ele:graph[i]) dfs(ele.second, ele.first+d);
}

int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
	depth.assign(n, 1e9);
	graph.assign(n, vector<pii>());
	vis.assign(n, 0);
	vis2.assign(n, 0);
	vector<int> ind(n, 0);
	for (int i = 0; i < M; i++)
	{
		graph[A[i]].push_back({B[i], T[i]});
		graph[B[i]].push_back({A[i], T[i]});
		ind[A[i]]++;
		ind[B[i]]++;
	}
	int sol = 0;
	vector<int> nodes;
	for (int i = 0; i < N; i++)
	{
		if (vis[i]) continue;
		nums.clear();
		dfs(i);
		int mx = 0;
		priority_queue<pii, vector<pii>, greater<pii>> pq;
		for (int ele:nums) if (ind[ele]==1) pq.push({0, ele});
		while(pq.size());
		{
			int j, d;
			tie(d, j) = pq.top();
			pq.pop();
			if (vis2[j]) continue;
			vis2[j] = 1;
			mx = max(mx, d);
			for (pii ele:graph[j])
			{	
				pq.push({d+ele.second, ele.first});
			}
		}
		int mmx = 0;
		int emx = 0;
		for (int ele:nums) 
		{
			if (depth[ele]>mmx)
			{
				mmx = depth[ele];
				emx = ele;	
			}
			vis[ele] = 0;
		}
		dfs(emx, 0);
		for (int ele:nums) 
		{
			mmx = max(mmx, emx);
		}

		nodes.push_back(mx);
		sol = max(sol, mmx);
	}
	sort(nodes.begin(), nodes.end());
	if (nodes.size()==2) sol = max(sol, nodes[0]+nodes[1]);
	else if (nodes.size()>2) sol = max(sol, nodes[0]+nodes[nodes.size()-2]+nodes.back());
	return sol;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:24:15: error: 'n' was not declared in this scope
   24 |  depth.assign(n, 1e9);
      |               ^
dreaming.cpp:42:8: error: too few arguments to function 'void dfs(int, int)'
   42 |   dfs(i);
      |        ^
dreaming.cpp:13:6: note: declared here
   13 | void dfs(int i, int d)
      |      ^~~
dreaming.cpp:46:3: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   46 |   while(pq.size());
      |   ^~~~~
dreaming.cpp:47:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   47 |   {
      |   ^
dreaming.cpp:71:12: warning: unused variable 'ele' [-Wunused-variable]
   71 |   for (int ele:nums)
      |            ^~~