暴力/图论 hihoCoder 1179 永恒游戏

 

题目传送门

 1 /*  2  暴力:也是暴力过了,无语。无向图,两端点都要加度数和点  3 */  4 #include <cstdio>  5 #include <algorithm>  6 #include <cstring>  7 #include <vector>  8 #include <cmath>  9 using namespace std; 10 11 typedef long long ll; 12 const int MAXN = 2e2 + 10; 13 const int INF = 0x3f3f3f3f; 14 ll a[MAXN]; 15 vector<int> G[MAXN]; 16 int degree[MAXN]; 17 18 int main(void) //hihoCoder 1179 永恒游戏 19 { 20 // freopen ("C.in", "r", stdin); 21 22 int n, m; 23 while (scanf ("%d%d", &n, &m) == 2) 24  { 25 for (int i=0; i<n; ++i) scanf ("%lld", &a[i]); 26 for (int i=0; i<n; ++i) G[i].clear (); 27 memset (degree, 0, sizeof (degree)); 28 while (m--) 29  { 30 int u, v; scanf ("%d%d", &u, &v); 31 degree[u]++; degree[v]++; 32  G[u].push_back (v); G[v].push_back (u); 33  } 34 35 bool ok = false; 36 for (int i=1; i<=100001; ++i) 37  { 38 ok = false; 39 for (int j=0; j<n; ++j) 40  { 41 if (a[j] >= degree[j]) 42  { 43 for (int k=0; k<G[j].size (); ++k) 44  { 45 a[j]--; a[G[j][k]]++; 46  } 47 ok = true; break; 48  } 49  } 50 if (!ok) {printf ("%d\n", i - 1); break;} 51  } 52 if (ok) puts ("INF"); 53  } 54 55 return 0; 56 }

 

你可能感兴趣的:(code)