Submission #64288945
Source Code Expand
Copy
#include <iostream>#include <queue>using namespace std;int main() {int n, m;cin >> n >> m;vector<vector<int>> graph(n, vector<int>());for (int i = 0; i < m; i++) {int u, v;cin >> u >> v;u--; v--;graph[u].push_back(v);graph[v].push_back(u);}vector<bool> used(n);int s = 0;for (int i = 0; i < n; i++) {if (!used[i]) {s++;queue<int> que;
#include <iostream>
#include <queue>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> graph(n, vector<int>());
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--; v--;
graph[u].push_back(v);
graph[v].push_back(u);
}
vector<bool> used(n);
int s = 0;
for (int i = 0; i < n; i++) {
if (!used[i]) {
s++;
queue<int> que;
que.push(i);
while (!que.empty()) {
int q = que.front(); que.pop();
for (int v : graph[q]) {
if (!used[v]) {
used[v] = true;
que.push(v);
}
}
}
}
}
cout << m - n + s << '\n';
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Make it Forest |
| User | kangping |
| Language | C++ 17 (gcc 12.2) |
| Score | 350 |
| Code Size | 640 Byte |
| Status | AC |
| Exec Time | 151 ms |
| Memory | 13448 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 350 / 350 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 02_min_00.txt, 02_min_01.txt, 03_max_00.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3456 KiB |
| 00_sample_01.txt | AC | 1 ms | 3436 KiB |
| 00_sample_02.txt | AC | 1 ms | 3640 KiB |
| 01_random_00.txt | AC | 130 ms | 11340 KiB |
| 01_random_01.txt | AC | 116 ms | 12812 KiB |
| 01_random_02.txt | AC | 148 ms | 13176 KiB |
| 01_random_03.txt | AC | 151 ms | 13440 KiB |
| 01_random_04.txt | AC | 122 ms | 10024 KiB |
| 01_random_05.txt | AC | 109 ms | 12540 KiB |
| 01_random_06.txt | AC | 142 ms | 10468 KiB |
| 01_random_07.txt | AC | 150 ms | 13448 KiB |
| 01_random_08.txt | AC | 98 ms | 9848 KiB |
| 01_random_09.txt | AC | 114 ms | 12636 KiB |
| 01_random_10.txt | AC | 133 ms | 10500 KiB |
| 01_random_11.txt | AC | 148 ms | 13352 KiB |
| 02_min_00.txt | AC | 1 ms | 3528 KiB |
| 02_min_01.txt | AC | 8 ms | 7832 KiB |
| 03_max_00.txt | AC | 52 ms | 6212 KiB |