답안 #433209

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
433209 2021-06-19T08:33:46 Z hibye1217 꿈 (IOI13_dreaming) C++17
컴파일 오류
0 ms 0 KB
/// dreaming.h   ///

#ifndef __DREAMING_H__
#define __DREAMING_H__

#ifdef __cplusplus
extern "C" {
#endif

int travelTime(int N, int M, int L, int A[], int B[], int T[]);

#ifdef __cplusplus
}
#endif

#endif /* __DREAMING_H__ */


///   grader.c   ///

#include <stdio.h>
#include <stdlib.h>
//#include "dreaming.h"

#define MAX_N 100000

static int A[MAX_N];
static int B[MAX_N];
static int T[MAX_N];

int main() {
	int N, M, L, i;
	int res;

	FILE *f = fopen("dreaming.in", "r");

	res = fscanf(f, "%d%d%d", &N, &M, &L);
	for (i = 0; i < M; i++)
		res = fscanf(f, "%d%d%d", &A[i], &B[i], &T[i]);
	fclose(f);

	int answer = travelTime(N, M, L, A, B, T);
	printf("%d\n", answer);

	return 0;
}

/// NOT SUBMIT ///
#define NOTSUBMIT
#include <bits/stdc++.h>
using namespace std;

/// dreaming.cpp ///

#ifndef NOTSUBMIT
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#endif // NOTSUBMIT

typedef long long ll;
typedef pair<ll, ll> pl2;
#define fr first
#define sc second

#define all(v) v.begin(),v.end()

vector<pl2> adj[100020];
int par[100020];

inline int fnd(int a){
	if (par[a] == a){ return a; }
	return par[a] = fnd(par[a]);
}

inline void uni(int a, int b){
	int pa = fnd(a), pb = fnd(b);
	par[pa] = pb;
}

vector<int> upd;
pl2 res = {-1, -1};
void dfs1(int now, int pre, ll dis){
	upd.push_back(now);
	if (res.sc < dis){ res = {now, dis}; }
	for (pl2 p : adj[now]){
		int nxt = p.fr; ll dst = p.sc;
		if (nxt == pre){ continue; }
		dfs1(nxt, now, dis+dst);
	}
}

pl2 chk[100020];
void dfs2(int now, int pre, ll dis){
	chk[now] = {pre, dis};
	if (res.sc < dis){ res = {now, dis}; }
	for (pl2 p : adj[now]){
		int nxt = p.fr; ll dst = p.sc;
		if (nxt == pre){ continue; }
		dfs2(nxt, now, dis+dst);
	}
}

bool pac[100020];
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	for (int i = 0; i < N; i++){ par[i] = i; }
	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] });
		uni(A[i], B[i]);
	}
	vector<ll> ansv;
	ll ret = 0;
	for (int i = 0; i < N; i++){
		int pai = fnd(i);
		if (pac[pai]){ continue; } pac[pai] = 1;
		res = {-1, -1}; dfs1(i, -1, 0); int mxp = res.fr;
		res = {-1, -1}; dfs2(mxp, -1, 0); int p = res.fr;
		vector<int> v;
		while (p != -1){ v.push_back(p); p = chk[p].fr; }
		int vl = v.size(); vector<ll> prf(vl);
		for (int i = 0; i < vl; i++){
			prf[i] = chk[ v[i] ].sc;
			ret = max(ret, prf[i]);
		}
		ll ans = 1e15;
		for (int i = 0; i < vl; i++){
			ll res = max( abs(prf[0]-prf[i]), abs(prf[i]-prf[vl-1]) );
			ans = min(ans, res);
		}
		//cout << "ANSV " << i << ' ' << ans << endl;
		ansv.push_back(ans);
	}
	sort(all(ansv), [](ll a, ll b){ return a > b; });
	if (ansv.size() == 1){ ret = max(ret, ansv[0]); }
	else if (ansv.size() == 2){ ret = max(ret, ansv[0]+L+ansv[1]); }
	else{ ret = max({ ret, ansv[0]+L+ansv[1], ansv[1]+L+L+ansv[2] }); }
	return ret;
}

Compilation message

dreaming.cpp: In function 'int main()':
dreaming.cpp:33:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   33 |  int res;
      |      ^~~
/usr/bin/ld: /tmp/ccorwqaK.o: in function `main':
dreaming.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccuTCWlM.o:grader.c:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status