답안 #416143

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
416143 2021-06-02T05:16:37 Z DEQK 꿈 (IOI13_dreaming) C++17
컴파일 오류
0 ms 0 KB
#include "dreaming.h"
#include <bits/stdc++.h>
 
#define ll long long
#define int ll
using namespace std;
const int N = 100100;
/*int travelTime(int n,int m,int l,vector<int> a,vector<int> b,vector<int> t) {
	
}*/
int n, m, l, ans;
int us[N], dp[N], was[N];
vector<pair<int, int>> g[N];
pair<int, int> best;
void dfs(int u) {
	us[u] = 1;
	for(auto to : g[u]) if(!us[to.first]) {
		dfs(to.first);
		dp[u] = max(dp[u], dp[to.first] + to.second);
	}
}
void dfs2(int u,int val) {
	was[u] = 1;
	vector<int> p, s;
	ans = max(ans, max(dp[u], val));
	if(best.first > max(dp[u], val)) {
		best = {max(dp[u], val), u};
	}
	for(int i = 0; i < g[u].size(); ++i) {
		int to = g[u][i].first, c = g[u][i].second;
		if(was[to]) continue;
		p.push_back(!p.empty() ? max(p.back(), dp[to] + c) : dp[to] + c);
	}
	for(int i = g[u].size() - 1; i >= 0; i--) {
		int to = g[u][i].first, c = g[u][i].second;
		if(was[to]) continue;
		s.push_back(s.empty() ? dp[to] + c : max(s.back(), dp[to] + c));
	}
	reverse(s.begin(), s.end());
	int q = -1;
	for(int i = 0; i < g[u].size(); i++) {
		int to = g[u][i].first, c = g[u][i].second;
		if(was[to]) continue;
		int f = val;
		++q;
		if(q) f = max(f, p[q - 1]);
		if(q + 1 < s.size()) f = max(f, s[q + 1]);
		dfs2(to, f + c);
	}
}
int travelTime(int n,int m,int l,int a[],int b[],int t[]) {
	for(int i = 0; i < m; ++i) {
		int u = a[i],v = b[i],w = t[i];
		g[u].push_back({v, w});
		g[v].push_back({u, w});
	}	
	vector<pair<int, int>> d;	
	for(int i = 0; i < n; ++i) {
		if(!us[i]) {
			dfs(i);
			best = {1e18, 0};
			dfs2(i, 0);
			d.push_back(best);
		}
	}
	sort(d.begin(), d.end(), [&] (pair<int, int> &x, pair<int, int> &y) {
		return x.first > y.first;
	});
	if(d.size() > 1) {
		ans = max(ans, d[0].first + d[1].first + l);
	}
	if(d.size() > 2) {
		ans = max(ans, d[1].first + d[2].first + 2 * l);
	}
	return ans;
}

Compilation message

dreaming.cpp: In function 'void dfs2(long long int, long long int)':
dreaming.cpp:29:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for(int i = 0; i < g[u].size(); ++i) {
      |                 ~~^~~~~~~~~~~~~
dreaming.cpp:41:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for(int i = 0; i < g[u].size(); i++) {
      |                 ~~^~~~~~~~~~~~~
dreaming.cpp:47:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   if(q + 1 < s.size()) f = max(f, s[q + 1]);
      |      ~~~~~~^~~~~~~~~~
/usr/bin/ld: /tmp/ccUj4SCg.o: in function `main':
grader.c:(.text.startup+0xd1): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status