Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
using namespace std; const int maxn = 3e5 + 10; int n; int parent[maxn]; int graph[maxn]; bool is_deleted[maxn]; int furthest_from_node[maxn]; int find_root(int x) { while(x != parent[x]) { parent[x] = parent[parent[x]]; x = parent[x]; } return x; } void unite(int x) { int y = find_root(graph[x]); if(x == y) { furthest_from_node[x] = -1; } parent[x] = y; } int main(){ ios_base::sync_with_stdio(false); cin >> n; for(int i = 1; i <= n; i++) { cin >> graph[i]; parent[i] = i; is_deleted[i] = false; } vector
> queries; int q; cin >> q; for(int i = 0; i < q; i++) { int a, b; cin >> a >> b; if(a == 2) { is_deleted[b] = true; } queries.push_back(make_pair(a, b)); } for(int i = 1; i <= n; i++) { if(!is_deleted[i] and graph[i] != 0) { unite(i); } } vector
ans; for(int i = q - 1; i >= 0; i--) { if(queries[i].first == 1) { int root = find_root(queries[i].second); if(furthest_from_node[root] == -1) { ans.push_back(-1); } else { ans.push_back(root); } } else { unite(queries[i].second); } } for(int i = (int) ans.size() - 1; i >= 0; i--) { if(ans[i] == -1) { cout << "CIKLUS\n"; } else { cout << ans[i] << "\n"; } } return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)