Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define D(x) cout << #x << " = " << (x) << endl
- #define fr freopen("in.txt", "r", stdin);
- #define fw freopen("out.txt", "w", stdout);
- #define mem(x) memset((x), 0, sizeof((x)));
- #define MAX 160000
- vector<int> edges[MAX];
- vector<int> cost[MAX];
- int connected = 0;
- bool visited[MAX];
- void dfs(int s) {
- visited[s] = true;
- for(int i = 0; i < edges[s].size(); ++i) {
- if(visited[edges[s][i]] == false) {
- connected++;
- dfs(edges[s][i]);
- }
- }
- }
- void initialize() {
- memset(visited, false, sizeof(visited));
- }
- int main() {
- int tc;
- cin >> tc;
- for(int tr = 1; tr <= tc; tr++) {
- printf("Case %d:\n", tr);
- //Graph Input;
- int n, e;
- scanf("%d %d", &n, &e);
- for(int i = 0; i < e; i++) {
- int u, v, w;
- scanf("%d %d %d", &u, &v, &w);
- edges[u].push_back(v);
- edges[v].push_back(u);
- cost[u].push_back(w);
- cost[v].push_back(w);
- }
- //
- //Erasing Code
- int q;
- cin >> q;
- for(int x = 0; x < q; x++) {
- int del;
- cin >> del;
- for(int i = 1; i <= n; i++) {
- for(int j = 0; j < edges[i].size(); j++) {
- if(cost[i][j] < del) {
- edges[i].erase(edges[i].begin()+j);
- // cout <<"Double bal" << endl;
- }
- }
- }
- //Connected component
- initialize();
- dfs(1);
- cout << connected << endl;
- connected = 0;
- }
- for(int i = 0; i < MAX; i++){
- edges[i].clear();
- cost[i].clear();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement