Submission #304591

#TimeUsernameProblemLanguageResultExecution timeMemory
304591rocks03Islands (IOI08_islands)C++14
0 / 100
18 ms23968 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pld pair<long double, int> #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define ff first #define ss second #define SZ(x) ((int)(x).size()) #define ld long double mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MAXN = 1e6+100; int N; vector<pii> adj[MAXN]; void read(){ cin >> N; for(int i = 0; i < N; i++){ int u, w; cin >> u >> w; --u; adj[i].pb({u, w}); adj[u].pb({i, w}); } } bool vis[MAXN], vis2[MAXN]; vector<int> componente; void dfs(int v){ vis[v] = true; componente.pb(v); for(auto u : adj[v]){ if(!vis[u.ff]){ dfs(u.ff); } } } ll dfs2(int v){ ll ans = 0; vis2[v] = true; for(auto u : adj[v]){ if(!vis2[u.ff]){ ans = max(ans, dfs2(u.ff) + u.ss); } } vis2[v] = false; return ans; } void solve(){ read(); ll ans = 0; for(int i = 0; i < N; i++){ if(!vis[i]){ dfs(i); ll res = 0; for(auto v : componente){ res = max(res, dfs2(v)); } ans += res; componente.clear(); } } cout << ans; } int main(){ freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }

Compilation message (stderr)

islands.cpp: In function 'int main()':
islands.cpp:72:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   72 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
islands.cpp:73:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   73 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...