Submission #1056496

# Submission time Handle Problem Language Result Execution time Memory
1056496 2024-08-13T09:47:16 Z lovrot Islands (IOI08_islands) C++17
0 / 100
149 ms 75580 KB
#include <cstdio> 
#include <vector>
#include <algorithm> 
#include <set>

#define debug(...) //fprintf(stderr, __VA_ARGS__)
#define X first
#define Y second
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e6 + 10;

int n, weg[N]; 
vector<pii> g[N];

char bio[N];
int cyci;
pii cyc[N];

void push_back(pii a) { 
	cyc[cyci++] = a;
}

void clear() {
	cyci = 0;
}

int dfs(int u, int p) { 
	bio[u] = 1;
	for(pii e : g[u]) { 
		int v = e.X, w = e.Y;
		if(w != p) { 
			if(bio[v]) { 
				push_back({e.X, weg[e.Y]});
//				cyc.PB({e.X, weg[e.Y]});
				return v;
			} else {
				int res = dfs(v, w);
				if(res) { 
					push_back({e.X, weg[e.Y]});					
//					cyc.PB({e.X, weg[e.Y]});
					return res != u ? res : 0;
				}
			}
		}
	}
	bio[u] = 0;
	return 0;
}

void mark(int u) { 
	bio[u] = 2;
	for(pii e : g[u]) { 
		if(bio[e.X] != 2) { 
			mark(e.X);
		}
	}
}

ll dep[N], ans_;

ll depth(int u, int p) { 
	ll max_ = 0;
	for(pii e : g[u]) { 
		int v = e.X, w = e.Y;
		if(w != p && !bio[v]) { 
			ll res = (ll) weg[w] + depth(v, w);
			if(dep[u] < res) { 
				max_ = dep[u]; 
				dep[u] = res;
			} else if(max_ < res) { 
				max_ = res;
			}
		}
	}
	ans_ = max(ans_, dep[u] + max_);
	return dep[u];
}

multiset<ll> s;

int main() { 
	scanf("%d", &n);

	for(int i = 1; i <= n; ++i) { 
		int u;
		scanf("%d%d", &u, weg + i);
		g[i].PB({u, i});
		g[u].PB({i, i});
	}
	
	return 0;
	ll ans = 0;
	for(int i = 1; i <= n; ++i) { 
		if(bio[i]) { continue; }

		clear();
//		s.clear();
		ans_ = 0;
		dfs(i, 0);

		for(int j = 0; j < cyci; ++j) { 
			pii e = cyc[j];
			depth(e.X, 0);
//			debug("%d(%d, %lld)\n", e.X, e.Y, dep[e.X]);
		}

		mark(i);
		
//		ll prf = 0;
//		for(int j = 0; j < cyci; ++j) { 
//			int v = cyc[j].X, w = cyc[j].Y;	
//			s.insert(dep[v] + prf);
//			prf += w;
//		}
//
//		ll prf_ = 0, len = prf;
//		for(int j = 0; j < cyci; ++j) { 
//			int v = cyc[j].X, w = cyc[j].Y;	
//			s.erase(s.find(dep[v] + prf - len));
//
//			ans_ = max(ans_, *prev(s.end()) + dep[v] - prf + len);
//
//			s.insert(dep[v] + prf);
//			prf += w;
//		}
//
//		ans += ans_;
	}

	printf("%lld\n", ans);
	return 0;
}

Compilation message

islands.cpp: In function 'int main()':
islands.cpp:88:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
islands.cpp:92:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |   scanf("%d%d", &u, weg + i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 26972 KB Output isn't correct
2 Incorrect 3 ms 26968 KB Output isn't correct
3 Incorrect 3 ms 26972 KB Output isn't correct
4 Incorrect 3 ms 26972 KB Output isn't correct
5 Incorrect 3 ms 26972 KB Output isn't correct
6 Incorrect 4 ms 26972 KB Output isn't correct
7 Incorrect 3 ms 27076 KB Output isn't correct
8 Incorrect 3 ms 26968 KB Output isn't correct
9 Incorrect 3 ms 26972 KB Output isn't correct
10 Incorrect 3 ms 26972 KB Output isn't correct
11 Incorrect 3 ms 26972 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 26972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 26972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 27480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 28764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 34384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 41300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 148 ms 68016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 149 ms 75580 KB Output isn't correct
2 Halted 0 ms 0 KB -