답안 #757004

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
757004 2023-06-12T12:16:35 Z SanguineChameleon Islands (IOI08_islands) C++17
0 / 100
319 ms 97736 KB
#include <bits/stdc++.h>
using namespace std;

void just_do_it();

int main() {
	#ifdef KAMIRULEZ
		freopen("kamirulez.inp", "r", stdin);
		freopen("kamirulez.out", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	just_do_it();
	return 0;
}

const int maxn = 1e6 + 20;
int to[maxn];
pair<int, int> edges[maxn * 2];
int adj_pt[maxn];
int par[maxn];
int len[maxn];
int depth[maxn];
pair<long long, int> dp[maxn];
bool flag[maxn];
bool is_cycle[maxn];
vector<int> cycle;
vector<int> lens;
vector<long long> max_depth;

void dfs1(int u) {
	flag[u] = true;
	for (int pt = adj_pt[u]; edges[pt].first == u; pt++) {
		int id = edges[pt].second;
		if (id == par[u]) {
			continue;
		}
		int v = id ^ to[id] ^ u;
		if (!flag[v]) {
			depth[v] = depth[u] + 1;
			par[v] = id;
			dfs1(v);
		}
		else {
/*			if (depth[u] > depth[v]) {
				int cur = u;
				int cnt = 0;
				while (cur != v) {
					cnt++;
					//cycle.push_back(cur);
					//lens.push_back(len[par[cur].second]);
					cur = par[cur].first;
				}
				cnt++;
				assert(cnt < maxn);
				//cycle.push_back(v);
				//lens.push_back(len[id]);
			}*/
		}
	}
}

/*void dfs2(int u, int p) {
	dp[u] = make_pair(0, u);
	for (auto e: adj[u]) {
		int v = e.first;
		int id = e.second;
		if (v != p && !is_cycle[v]) {
			dfs2(v, u);
			dp[u] = max(dp[u], make_pair(dp[v].first + len[id], dp[v].second));
		}
	}
}*/

/*long long solve() {
	int n = cycle.size();
	for (int i = 0; i < n; i++) {
		is_cycle[cycle[i].u] = true;
	}
	long long res = 0;
	for (int i = 0; i < n; i++) {
		int u = cycle[i].u;
		is_cycle[u] = false;
		dfs2(u, -1);
		cycle[i].max_depth = max_depth[u].first;
		int v = max_depth[u].second;
		dfs2(v, -1);
		res = max(res, max_depth[v].first);
		is_cycle[u] = true;
	}
	vector<long long> dist(n);
	long long mx = cycle[0].max_depth;
	for (int i = 1; i < n; i++) {
		dist[i] = dist[i - 1] + cycle[i - 1].len;
		res = max(res, dist[i] + cycle[i].max_depth + mx);
		mx = max(mx, cycle[i].max_depth - dist[i]);
	}
	long long sum = dist[n - 1] + cycle[n - 1].len;
	mx = cycle[0].max_depth;
	for (int i = 1; i < n; i++) {
		res = max(res, (sum - dist[i]) + cycle[i].max_depth + mx);
		mx = max(mx, cycle[i].max_depth + dist[i]);
	}
	return res;
}*/

void just_do_it() {
	int n;
	cin >> n;
	assert(n <= 1000000);
	for (int i = 1; i <= n; i++) {
		cin >> to[i] >> len[i];
		edges[i * 2 - 1] = make_pair(i, i);
		edges[i * 2] = make_pair(to[i], i);
	}
	sort(edges + 1, edges + n * 2 + 1);
	for (int i = 1; i <= n * 2; i++) {
		if (edges[i].first != edges[i - 1].first) {
			adj_pt[edges[i].first] = i;
		}
	}
	long long res = 0;
	for (int u = 1; u <= n; u++) {
		if (!flag[u]) {
			//cycle.clear();
			//lens.clear();
			//max_depth.clear();
			par[u] = -1;
			dfs1(u);
			//res += solve();
		}
	}
	cout << res;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Incorrect 0 ms 340 KB Output isn't correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Incorrect 0 ms 340 KB Output isn't correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Incorrect 1 ms 340 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 1040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 3416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 8736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 97 ms 15728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 319 ms 36468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 277 ms 97736 KB Output isn't correct
2 Halted 0 ms 0 KB -