답안 #527635

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527635 2022-02-17T21:06:12 Z Hanksburger 꿈 (IOI13_dreaming) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > adj[100005];
vector<int> vec, centers;
int sz[100005], n, m, l;
bool visited[100005];
void dfs(int u, int prev)
{
	visited[u]=1;
	vec.push_back(u);
	for (int i=0; i<adj[u].size(); i++)
	{
		int v=adj[u][i].first, w=adj[u][i].second;
		if (v==prev)
			continue;
		dfs(v, u);
		sz[u]+=sz[v]+w;
	}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
    n=N;
    m=M;
    l=L;
    for (int i=0; i<m; i++)
    {
    	adj[A[i]].push_back({B[i], T[i]});
    	adj[B[i]].push_back({A[i], T[i]});
	}
	for (int i=0; i<n; i++)
	{
		if (visited[i])
			continue;
		vec.clear();
		dfs(i, -1);
		int center=1e9;
		for (int j=0; j<vec.size(); j++)
		{
			int u=vec[j];
			int maxi=sz[i]-sz[u];
//			cout << "j " << j << '\n';
//			cout << "maxi " << maxi << '\n';
			for (int k=0; k<adj[u].size(); k++)
			{
				int v=adj[u][k].first, w=adj[u][k].second;
				if (sz[u]>sz[v])
					maxi=max(maxi, sz[v]+w);
//				cout << "maxi " << maxi << '\n';
			}
			center=min(center, maxi);
		}
		centers.push_back(center);
//		cout << "i center " << i << ' ' << center << '\n';
	}
	sort(centers.begin(), centers.end(), greater<int>());
	if (centers.size()==1)
		return 0;
	else if (centers.size()==2)
		return centers[0]+centers[1]+l;
	else
		return max(centers[0]+centers[1]+l, centers[1]+centers[2]+l*2);
}

Compilation message

dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:11:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |  for (int i=0; i<adj[u].size(); i++)
      |                ~^~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:37:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for (int j=0; j<vec.size(); j++)
      |                 ~^~~~~~~~~~~
dreaming.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |    for (int k=0; k<adj[u].size(); k++)
      |                  ~^~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccC8X5lu.o: in function `main':
grader.c:(.text.startup+0xd1): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status