正文
增加 14 行删除 14 行
32 行未改动3334353637383940414243444546474844 行未改动9394959697989910010110 行未改动11211311411511611711811912012112212312412512612712812913013113213339 行未改动17317417517617717817918018118218318418518618718818919019119219319419519619719819920020125 行未改动22722822923023123223323423523632 行未改动bool is_forest(int n, int m) {vector<int> parent(n, -1);vector<bool> visited(n, false);bool has_cycle = false;for (int i = 0; i < n; i++) {if (!visited[i]) {queue<int> q;q.push(i);visited[i] = true;parent[i] = -1;while (!q.empty()) {int u = q.front(); q.pop();for (int v : g[u]) {if (!visited[v]) {44 行未改动if (color[i] == -1) {color[i] = 0;queue<int> q;q.push(i);while (!q.empty()) {int u = q.front(); q.pop();for (int v : g[u]) {if (color[v] == -1) {10 行未改动}bool is_cactus(int n, int m) {if (m > 2 * n - 2) return false;vector<int> parent(n, -1);vector<int> depth(n, 0);vector<bool> visited(n, false);vector<int> cycle_count(n, 0);for (int i = 0; i < n; i++) {if (!visited[i]) {queue<int> q;q.push(i);visited[i] = true;parent[i] = -1;depth[i] = 0;while (!q.empty()) {int u = q.front(); q.pop();for (int v : g[u]) {if (!visited[v]) {39 行未改动int main() {ios::sync_with_stdio(false);cin.tie(nullptr);int T;cin >> T;while (T--) {int n, m;cin >> n >> m;g.assign(n, vector<int>());vis.assign(n, false);for (int i = 0; i < m; i++) {int u, v;cin >> u >> v;u--; v--;g[u].push_back(v);g[v].push_back(u);}char ans;if (is_graph_empty(n, m)) {ans = 'G';}else if (is_star(n, m)) {25 行未改动}else {ans = 'G';}cout << ans << '\n';}return 0;}32 行未改动3334353637383940414243444546474844 行未改动9394959697989910010110 行未改动11211311411511611711811912012112212312412512612712812913013113213339 行未改动17317417517617717817918018118218318418518618718818919019119219319419519619719819920020125 行未改动22722822923023123223323423523632 行未改动bool is_forest(int n, int m) {vector<int> parent(n, -1);vector<bool> visited(n, false);bool has_cycle = false;for (int i = 0; i < n; i++) {if (!visited[i]) {queue<int> q;q.push(i);visited[i] = true;parent[i] = -1;while (!q.empty()) {int u = q.front(); q.pop();for (int v : g[u]) {if (!visited[v]) {44 行未改动if (color[i] == -1) {color[i] = 0;queue<int> q;q.push(i);while (!q.empty()) {int u = q.front(); q.pop();for (int v : g[u]) {if (color[v] == -1) {10 行未改动}bool is_cactus(int n, int m) {if (m > 2 * n - 2) return false;vector<int> parent(n, -1);vector<int> depth(n, 0);vector<bool> visited(n, false);vector<int> cycle_count(n, 0);for (int i = 0; i < n; i++) {if (!visited[i]) {queue<int> q;q.push(i);visited[i] = true;parent[i] = -1;depth[i] = 0;while (!q.empty()) {int u = q.front(); q.pop();for (int v : g[u]) {if (!visited[v]) {39 行未改动int main() {ios::sync_with_stdio(false);cin.tie(nullptr);int T;cin >> T;while (T--) {int n, m;cin >> n >> m;g.assign(n, vector<int>());vis.assign(n, false);for (int i = 0; i < m; i++) {int u, v;cin >> u >> v;u--; v--;g[u].push_back(v);g[v].push_back(u);}char ans;if (is_graph_empty(n, m)) {ans = 'G';}else if (is_star(n, m)) {25 行未改动}else {ans = 'G';}cout << ans << '\n';}return 0;}