제출 #655398

#제출 시각아이디문제언어결과실행 시간메모리
655398ShirAriel연결리스트 수사하기 (NOI12_forensic)C++17
20 / 25
3 ms1492 KiB
#include <iostream> #include <algorithm> #include <vector> using namespace std; typedef long long ll; vector<vector<ll>> branch; vector<bool> visited; ll getlen(ll v) { ll ans = 0; visited[v] = true; for (ll i = 0; i < branch[v].size(); i++) { ll u = branch[v][i]; if (!visited[u]) ans = max(getlen(u) + 1, ans); } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; cin >> n; vector<ll> chain(n); for (ll i = 0; i < n; i++) cin >> chain[i]; branch.resize(n); for (ll i = 0; i < n; i++) if (chain[i] != -1) branch[chain[i]].push_back(i); ll b = 0, c = 0; bool circle = false; visited.resize(n, false); ll v = chain[0], cnt=1; visited[0] = true; while (v!=-1 && !visited[v]) { visited[v] = true; b = max(b, getlen(v)); v = chain[v]; cnt++; } if (v!=-1) circle = true; for (ll i = 0; i < n; i++) if (chain[i] == -1 && !visited[i]) c = max(c, getlen(i) + 1); cout << cnt + max(c, (circle ? 0 : b)); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

forensic.cpp: In function 'll getlen(ll)':
forensic.cpp:17:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for (ll i = 0; i < branch[v].size(); i++)
      |                 ~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...