Submission #439905

# Submission time Handle Problem Language Result Execution time Memory
439905 2021-07-01T07:15:42 Z dutch Islands (IOI08_islands) C++17
0 / 100
434 ms 131076 KB
#include <bits/stdc++.h>
using namespace std;

const int LIM = 1e6;

vector<array<int, 2>> a(LIM), g[LIM];
bitset<LIM> vis;
pair<long long, int> c;
long long toRoot;
int r;

void dfs(int u, int p, long long d){
	vis[u] = 1, c = max(c, {d, u});
	for(auto &[v, w] : g[u]) if(v != p){
		if(v == r) toRoot = d;
		else dfs(v, u, d + (long long)w);
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;

	for(int i=0; i<n; ++i){
		cin >> a[i][0] >> a[i][1];
		g[--a[i][0]].push_back({i, a[i][1]});
	}

	long long ans = 0;

	for(r=0; r<n; ++r){
		if(vis[r]) continue;
		dfs(r, r, 0);
		long long curr = toRoot + a[r][1];
		dfs(c.second, -1, 0);
		curr = max(curr, c.first);
		ans += curr;
	}

	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 31576 KB Output isn't correct
2 Incorrect 20 ms 31648 KB Output isn't correct
3 Incorrect 23 ms 31648 KB Output isn't correct
4 Incorrect 20 ms 31564 KB Output isn't correct
5 Runtime error 84 ms 131076 KB Execution killed with signal 9
6 Runtime error 75 ms 131076 KB Execution killed with signal 9
7 Runtime error 81 ms 131076 KB Execution killed with signal 9
8 Runtime error 84 ms 131076 KB Execution killed with signal 9
9 Runtime error 81 ms 131076 KB Execution killed with signal 9
10 Incorrect 20 ms 31636 KB Output isn't correct
11 Incorrect 19 ms 31560 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 31692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 92 ms 131076 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 142 ms 131076 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 34056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 94 ms 38868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 191 ms 131076 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 347 ms 55388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 434 ms 125372 KB Output isn't correct
2 Halted 0 ms 0 KB -