Untitled
unknown
c_cpp
a year ago
1.1 kB
6
Indexable
#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 200001;
vector <int> V[N];
bool vis[N];
int ans = 0;
void dfs(int s) {
vis[s] = true;
for (auto child : V[s]) {
if (!vis[child]) {
ans++;
dfs(child);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
memset(vis, false, sizeof(vis));
memset(V, 0, sizeof(V));
cin >> n;
int m;
cin >> m;
while(m--) {
int a, b, k;
cin >> a >> b >> k;
for (int i = 1; i <= k; i++) {
V[a].push_back(a + i*b);
V[a + i*b].push_back(a);
}
}
int total = n;
for(int i = 1; i <= n; i++) {
if (!V[i].empty()) {
ans = 0;
dfs(i);
total -= (ans);
}
}
cout << total << "\n";
}
return 0;
}Editor is loading...
Leave a Comment