Submission #1312991

#TimeUsernameProblemLanguageResultExecution timeMemory
1312991levForensic (NOI12_forensic)C++20
0 / 25
2 ms2360 KiB
#include <bits/stdc++.h> // Kazusa_Megumi #define ll long long #define fi first #define se second #define pii pair<int, int> #define all(a) a.begin(), a.end() using namespace std; #ifdef LOCAL #include "C:\Users\Dell\Downloads\template\template\icpc-notebook\Utilities\debug.h" #else #define debug(...) 42 #endif const int mn = 5e5 + 5, mod = 1e9 + 7, inf = 2e9; int n, nxt[mn], vis[mn], dp[mn], cnt = 0, loop = 0; void down(int u){ vis[u] = 1, dp[u] = 0; cnt ++; if(nxt[u] == -1) return; if(vis[nxt[u]]){ loop = 1; return; } down(nxt[u]); } int f(int u){ if(nxt[u] == -1) return 1; if((vis[nxt[u]] && loop) || u == 1) return - 1e9; if(dp[u] != -1) return dp[u]; dp[u] = 0; if(vis[u] == 1) return dp[u] = - 1e9; vis[u] = 1; dp[u] = f(nxt[u]) + 1; vis[u] = 2; return dp[u]; } void solve() { cin >> n; for(int i = 1; i <= n; i++){ cin >> nxt[i]; if(nxt[i] != -1) nxt[i] ++; } down(1); memset(dp, -1, sizeof(dp)); int ans = - 1e9; for(int i = 1; i <= n; i++){ if(!vis[i]){ debug(i, f(i)); ans = max(ans, f(i)); } } cout << ans + cnt << '\n'; } main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); if (fopen("Kazuki.INP", "r")) { freopen("Kazuki.INP", "r", stdin); freopen("Kazuki.OUT", "w", stdout); } int t = 1; // cin >> t; while (t--) solve(); return 0; }

Compilation message (stderr)

forensic.cpp:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   63 | main() {
      | ^~~~
forensic.cpp: In function 'int main()':
forensic.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen("Kazuki.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
forensic.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         freopen("Kazuki.OUT", "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...