답안 #897402

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
897402 2024-01-03T03:58:21 Z Muhammad_Aneeq 꿈 (IOI13_dreaming) C++17
14 / 100
1000 ms 13864 KB
#include <vector>
#include <algorithm>
#include "dreaming.h"
using namespace std;
int const N=1e5+10;
vector<pair<int,int>>nei[N]={};
vector<int>heads;
bool vis[N]={};
int cost[N]={};
void dfs(int n)
{
	vis[n]=1;
	for (auto [i,w]:nei[n])
	{
		if (!vis[i])
		{
			cost[n]+=w;
			dfs(i);
			cost[n]+=cost[i];
		}
	}
}
vector<pair<int,int>>cur={};
bool w=0;
void getroot(int n,int pa,int root)
{
	int f=cost[root]-cost[n];
	for (auto [i,w]:nei[n])
	{
		if (i!=pa)
		{
			f=max(f,cost[i]+w);
			getroot(i,n,root);
		}
		else
			f=max(f,cost[root]-cost[n]);
	}
	cur.push_back({f,n});
}
int travelTime(int n, int m, int l, int a[], int b[], int t[])
{
	for (int i=0;i<m;i++)
	{
		nei[a[i]].push_back({b[i],t[i]});
		nei[b[i]].push_back({a[i],t[i]});
	}
	for (int i=0;i<n;i++)
	{
		if (!vis[i])
		{
			heads.push_back(i);
			dfs(i);
		}
	}
	for (int i=0;i<n;i++)
		vis[i]={};
	vector<pair<int,int>>new_head;
	for (auto i:heads)
	{
		if (i!=heads[0])
			w=1;
		getroot(i,-1,i);
		sort(begin(cur),end(cur));
		new_head.push_back(cur[0]);
		cur={};
	}
	sort(begin(new_head),end(new_head));
	reverse(begin(new_head),end(new_head));
	for (int i=1;i<new_head.size();i++)
	{
		nei[new_head[0].second].push_back({new_head[i].second,l});
		nei[new_head[i].second].push_back({new_head[0].second,l});
	}
	int ans=new_head[0].first+new_head[1].first+l;
	for (int i=1;i<new_head.size();i++)
	{
		for (int j=i+1;j<new_head.size();j++)
			ans=max(ans,new_head[i].first+new_head[j].first+l+l);
	}
	for (auto i:heads)
		ans=max(ans,cost[i]);
	return ans;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:69:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |  for (int i=1;i<new_head.size();i++)
      |               ~^~~~~~~~~~~~~~~~
dreaming.cpp:75:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |  for (int i=1;i<new_head.size();i++)
      |               ~^~~~~~~~~~~~~~~~
dreaming.cpp:77: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]
   77 |   for (int j=i+1;j<new_head.size();j++)
      |                  ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 13864 KB Output is correct
2 Correct 35 ms 13376 KB Output is correct
3 Correct 24 ms 12248 KB Output is correct
4 Correct 6 ms 4956 KB Output is correct
5 Correct 5 ms 4188 KB Output is correct
6 Correct 9 ms 5740 KB Output is correct
7 Correct 2 ms 3420 KB Output is correct
8 Correct 17 ms 7656 KB Output is correct
9 Correct 24 ms 10460 KB Output is correct
10 Correct 1 ms 3420 KB Output is correct
11 Correct 31 ms 10596 KB Output is correct
12 Correct 44 ms 12508 KB Output is correct
13 Correct 1 ms 3420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 13864 KB Output is correct
2 Correct 35 ms 13376 KB Output is correct
3 Correct 24 ms 12248 KB Output is correct
4 Correct 6 ms 4956 KB Output is correct
5 Correct 5 ms 4188 KB Output is correct
6 Correct 9 ms 5740 KB Output is correct
7 Correct 2 ms 3420 KB Output is correct
8 Correct 17 ms 7656 KB Output is correct
9 Correct 24 ms 10460 KB Output is correct
10 Correct 1 ms 3420 KB Output is correct
11 Correct 31 ms 10596 KB Output is correct
12 Correct 44 ms 12508 KB Output is correct
13 Correct 1 ms 3420 KB Output is correct
14 Incorrect 1 ms 3416 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1056 ms 7948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 13864 KB Output is correct
2 Correct 35 ms 13376 KB Output is correct
3 Correct 24 ms 12248 KB Output is correct
4 Correct 6 ms 4956 KB Output is correct
5 Correct 5 ms 4188 KB Output is correct
6 Correct 9 ms 5740 KB Output is correct
7 Correct 2 ms 3420 KB Output is correct
8 Correct 17 ms 7656 KB Output is correct
9 Correct 24 ms 10460 KB Output is correct
10 Correct 1 ms 3420 KB Output is correct
11 Correct 31 ms 10596 KB Output is correct
12 Correct 44 ms 12508 KB Output is correct
13 Correct 1 ms 3420 KB Output is correct
14 Incorrect 1 ms 3416 KB Output isn't correct
15 Halted 0 ms 0 KB -