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
#include
#include
#include
#include
#include
using namespace std; const int maxn = 1e5 + 10; int n, m; vector
dangerous_graph[maxn]; vector
safe_graph[maxn]; int idx[maxn], sz[maxn]; int find_root(int x) { while(x != idx[x]) { idx[x] = idx[idx[x]]; x = idx[x]; } return x; } bool check(int a, int b) { if(find_root(a) == find_root(b)) { return true; } return false; } void unite(int a, int b) { int a_root = find_root(a); int b_root = find_root(b); if(a_root != b_root) { if(sz[a_root] < sz[b_root]) { idx[a_root] = idx[b_root]; sz[b_root] += sz[a_root]; } else { idx[b_root] = idx[a_root]; sz[a_root] += sz[b_root]; } } } int main() { for(int i = 0; i < maxn; i++) { idx[i] = i; sz[i] = 1; } cin >> n >> m; for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; dangerous_graph[a].push_back(b); dangerous_graph[b].push_back(a); unite(a, b); } int k; cin >> k; for(int i = 0; i < k; i++) { int a, b; cin >> a >> b; a--; b--; safe_graph[a].push_back(b); safe_graph[b].push_back(a); } for(int i = 0; i < n; i++) { int result = sz[find_root(i)] - 1; result -= (int) dangerous_graph[i].size(); // cout << i << " " << sz[find_root(i)] << " " << dangerous_graph[i].size() << endl; for(int j = 0; j < safe_graph[i].size(); j++) { int neighbour = safe_graph[i][j]; if(check(neighbour, i)) { result--; } } cout << result << endl; } return 0; } /* 10 9 1 6 1 9 1 10 2 6 2 7 3 7 4 8 4 9 5 10 */
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)