답안 #230711

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
230711 2020-05-11T09:41:32 Z islingr 꿈 (IOI13_dreaming) C++14
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(x, v) for (auto &x : v)

#define eb(x...) emplace_back(x)

using pii = pair<int, int>;

template<class T> bool ckmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, T b) { return a < b ? a = b, 1 : 0; }

constexpr int N = 1 << 17;
vector<pii> g[N];
int d[N], p[N], a, c[N], e[N];
bool vis[N];

void dfs(int u, int p = -1) {
	if (d[u] > d[a]) a = u;
	::p[u] = p;
	vis[u] = true;
	trav(e, g[u]) {
		int v, w; tie(v, w) = e;
		if (v == p) continue;
		d[v] = d[u] + w;
		dfs(v, u);
	}
}

int travelTime(int n, int m, int l, int A[], int B[], int T[]) {
	rep(i, 0, m) {
		g[A[i]].eb(B[i], T[i]);
		g[B[i]].eb(A[i], T[i]);
	}
	int one = 0, two = 0, cmp = 0;
	rep(u, 0, n) {
		if (vis[u]) continue;
		a = u; d[u] = 0; dfs(u); d[a] = 0; dfs(a);
		e[cmp] = d[a]; c[cmp] = a;	
		for (int v = a; p[v] != -1; v = p[v]) 
			if (ckmin(e[cmp], max(d[a] - d[v], d[v])))
				c[cmp] = v;
		++cmp;
	}
	int x = 0;
	rep(i, 0, cmp) if (e[i] > e[x]) x = i;
	rep(i, 0, cmp) {
		if (x == i) continue;
		g[x].eb(c[i], l);
		g[c[i]].eb(x, l);
	}
	a = 0; d[0] = 0; dfs(0); d[a] = 0; dfs(a);
	return d[a];
}

int A[N], B[N], T[N];

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, m, l; cin >> n >> m >> l;
	rep(i, 0, m) cin >> A[i] >> B[i] >> T[i];
	cout << travelTime(n, m, l, A, B, T);
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:38:6: warning: unused variable 'one' [-Wunused-variable]
  int one = 0, two = 0, cmp = 0;
      ^~~
dreaming.cpp:38:15: warning: unused variable 'two' [-Wunused-variable]
  int one = 0, two = 0, cmp = 0;
               ^~~
/tmp/cccnPW8O.o: In function `main':
dreaming.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccA9Koj9.o:grader.c:(.text.startup+0x0): first defined here
/tmp/ccA9Koj9.o: In function `main':
grader.c:(.text.startup+0xa2): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status