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
#include
//#include
using namespace std; const int maxn = 100005; vector
adj[maxn]; int owner[maxn]; //ke zemam 0 za nicija sopstvenost, 1 za kosta, 2 za kiril int distArr[maxn]; //plan: treba modificiran bfs za sekoja startna pozicija int bfs(vector
starts, int P) { queue
q; vector
visited(maxn, false); for (int s : starts) { q.push(s); distArr[s] = 0; visited[s] = true; } int cnt = 0; while (!q.empty()) { int u = q.front(); q.pop(); for (int v : adj[u]) { if(owner[v] == 2){ continue; } if(visited[v]){ continue; } visited[v] = true; if(owner[v] == 0){ owner[v] = 1; cnt++; } q.push(v); } } return cnt; } int main() { ios::sync_with_stdio(false); int n, b1, b2, p; cin >> n >> b1 >> b2 >> p; vector
kosta(b1), kiril(b2); for (int i = 0; i < b1; i++){ cin >> kosta[i]; owner[kosta[i]] = 1; } for (int i = 0; i < b2; i++){ cin >> kiril[i]; owner[kiril[i]] = 2; } int m; cin >> m; for (int i = 0; i < m; i++){ int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 1; i <= n; i++){ distArr[i] = -1; } int newCities = bfs(kosta, p); cout << min(newCities, p) << endl; 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)