hdu 5452
无意中看到这道题
没读懂英文题面
百度题解寻找题面
看到:
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <string> #include <cmath> #include <vector> using namespace std; #define gc getchar() inline int read() { int x = 0; char c = gc; while(c < '0' || c > '9') c = gc; while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc; return x; } const int N = 100010; int Cuttree[N], Cutnottree[N]; int n, m; int main() { for(int j = 1, T = read(); T; T --, j ++) { n = read(), m = read(); for(int i = 1; i <= n; i ++) Cuttree[i] = Cutnottree[i] = 0; for(int i = 1; i <= m; i ++) { int a = read(), b = read(); if(i < n) { Cuttree[a] ++; Cuttree[b] ++; } else { Cutnottree[a] ++; Cutnottree[b] ++; } } int Answer = 999999999; for(int i = 1; i <= n; i ++) if(Cuttree[i] == 1) Answer = min(Answer, Cuttree[i] + Cutnottree[i]); cout << "Case #" << j <<": " << Answer << "\n"; } return 0; }