It is the year 95 ACM (After the Crash of Microsoft). After many years of peace, a war has broken out. Your nation, the island of Evergreen Macros And Confusing Shortcuts (EMACS), is defending itself against the railway empire ruled by Visually Impaired Machinists (VIM).
这就是ACM的题目里面十分常见的一个景象——扩充缩写。这件事情是这么干的:已知一个缩写,比如ACM,我们找出一些词汇,让它们表达出一个含义,并且它的缩写是ACM,就像上文做的那样——After the Crash of Microsoft.
classV : public vector<int> { public: int index; int num, count; V(int idx = 0) :index(idx), num(-1), count(0) {
} booloperator < (const V &b) const { if (count != b.count){ return count > b.count; } else{ return index < b.index; } } }; intdfs(vector<V> &vs, V &v, int c){ v.num = c; int low = c; for (int u : v) { if (vs[u].num < 0) { int t = dfs(vs, vs[u], c + 1); low = min(low, t); if (v.num <= t) v.count++; } else low = min(low, vs[u].num); } return low; } voidsolve(int n, int m){ vector<V> vs; for (int i = 0; i < n; i++){ vs.push_back(V(i)); } int x, y; while (cin >> x >> y){ if (x < 0 && y < 0) break; vs[x].push_back(y); vs[y].push_back(x); } for (vector<V>::iterator it = vs.begin(); it != vs.end(); it++){ if ((*it).num < 0){ dfs(vs, *it, 0); if ((*it).count > 0){ (*it).count--; } } } sort(vs.begin(), vs.end()); for (int i = 0; i < m; i++){ cout << vs[i].index << ' ' << vs[i].count + 1 << 'n'; } } intmain(int agrc, char *agrv[]){ ios::sync_with_stdio(false); int n, m; while (cin >> n >> m, n m){ solve(n, m); cout << 'n'; } }