제출 #547602

#제출 시각아이디문제언어결과실행 시간메모리
547602OlympiaCat in a tree (BOI17_catinatree)C++17
100 / 100
163 ms16812 KiB
#include <cmath> #include <iostream> #include <set> #include <climits> #include <algorithm> #include <cassert> #include <vector> #include <iomanip> #include <type_traits> #include <string> #include <queue> #include <map> #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") using namespace std; vector<vector<int>> adj; vector<pair<int,int>> vec; vector<int> parent; vector<bool> isValid; vector<int> marked; vector<int> qr; bool comp (pair<int,int> p1, pair<int,int> p2) { return (p1.second > p2.second); } void go_down (int curNode, int d) { if (d == 0) return; if (marked[curNode] >= d) return; marked[curNode] = d; isValid[curNode] = false; for (int i: adj[curNode]) go_down(i, d - 1); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N, D; cin >> N >> D; adj.resize(N), vec.assign(N, {-1, -1}), isValid.assign(N, true), parent.resize(N), marked.assign(N, -1); for (int i = 1; i < N; i++) { int x; cin >> x; adj[x].push_back(i), adj[i].push_back(x); } queue<pair<int,int>> q; q.push({0, 0}); while (!q.empty()) { pair<int,int> pr = q.front(); q.pop(); if (vec[pr.first].first != -1) { continue; } vec[pr.first] = pr; for (int i: adj[pr.first]) { q.push({i, pr.second + 1}); } } sort(vec.begin(), vec.end(), comp); int ans = 0; for (auto& p: vec) { if (!isValid[p.first]) { continue; } ans++; go_down(p.first, D); } cout << ans; }

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

catinatree.cpp:15: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   15 | #pragma GCC optimization ("O3")
      | 
catinatree.cpp:16: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   16 | #pragma GCC optimization ("unroll-loops")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...