답안 #527636

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527636 2022-02-17T21:07:07 Z Hanksburger 꿈 (IOI13_dreaming) C++17
18 / 100
36 ms 12764 KB
#include "dreaming.h"
#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:12: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]
   12 |  for (int i=0; i<adj[u].size(); i++)
      |                ~^~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |   for (int j=0; j<vec.size(); j++)
      |                 ~^~~~~~~~~~~
dreaming.cpp:44: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]
   44 |    for (int k=0; k<adj[u].size(); k++)
      |                  ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 12764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 12764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 6184 KB Output is correct
2 Correct 17 ms 6220 KB Output is correct
3 Correct 25 ms 6216 KB Output is correct
4 Correct 22 ms 6200 KB Output is correct
5 Correct 17 ms 6200 KB Output is correct
6 Correct 18 ms 6596 KB Output is correct
7 Correct 18 ms 6380 KB Output is correct
8 Correct 16 ms 6060 KB Output is correct
9 Correct 29 ms 6032 KB Output is correct
10 Correct 20 ms 6340 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 4 ms 3664 KB Output is correct
13 Correct 4 ms 3656 KB Output is correct
14 Correct 4 ms 3656 KB Output is correct
15 Correct 4 ms 3656 KB Output is correct
16 Correct 4 ms 3656 KB Output is correct
17 Correct 4 ms 3400 KB Output is correct
18 Correct 5 ms 3676 KB Output is correct
19 Correct 4 ms 3656 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 3 ms 2648 KB Output is correct
23 Correct 4 ms 3540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 12764 KB Output isn't correct
2 Halted 0 ms 0 KB -