QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232221#7503. Too Many EdgesOAleksaTL 0ms6136kbC++141.7kb2023-10-30 05:27:382023-10-30 05:27:38

Judging History

你现在查看的是最新测评结果

  • [2023-10-30 05:27:38]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:6136kb
  • [2023-10-30 05:27:38]
  • 提交

answer

#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
#define int long long
const int maxn = 5e4 + 69;
vector<int> g[maxn];
int n, m, deg[maxn], par[maxn], cnt[maxn];
signed main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int tt = 1;
   //cin >> tt;
   while(tt--) {
		cin >> n >> m;
		set<pair<int, int>> edges;
		for (int i = 1;i <= m;i++) {
			int x, y;
			cin >> x >> y;
			if (x > y)
				swap(x, y);
			edges.insert({x, y});
		}
		int ans = 0;
		while (1) {
			for (int i = 1;i <= n;i++) {
				g[i].clear();
				deg[i] = cnt[i] = 0;
			}
			for (auto x : edges) {
				int a, b;
				tie(a, b) = x;
				g[a].push_back(b);
				deg[b]++;
			}
			queue<int> q;
			for (int i = 1;i <= n;i++) {
				if (deg[i] == 0)
					q.push(i);
			}
			while (!q.empty()) {
				auto v = q.front();
				q.pop();
				for (auto u : g[v]) {
					deg[u]--;
					if (cnt[v] + 1 >= cnt[u])
						par[u] = v;
					cnt[u] = max(cnt[u], cnt[v] + 1);
					if (deg[u] == 0)
						q.push(u);
				}
			}
			vector<int> v;
			int mx = 0, t;
			for (int i = 1;i <= n;i++) {
				if (cnt[i] >= mx) {
					t = i;
					mx = cnt[i];
				}
			}
			while (t != 0) {
				v.push_back(t);
				t = par[t];
			}
			reverse(v.begin(), v.end());
			int ok = 0;
			for (int i = 1;i < (int)v.size();i++) {
				int a = v[i - 1], b = v[i];
				if (a > b)
					swap(a, b);
				cout << "? " << v[i - 1] << " " << v[i] << endl;
				int r;
				cin >> r;
				if (r == 0) {
					edges.erase({a, b});
					ok = 1;
					break;
				}
			}
			if (!ok) {
				ans = mx;
				break;
			}
		}
		cout << "! " << ans << endl;
   }
   return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 6136kb

input:

5 5
1 2
1 3
2 5
3 4
4 5
1
0
1
1

output:

? 1 3
? 3 4
? 1 2
? 2 5
! 2

result:

ok Correct answer

Test #2:

score: -100
Time Limit Exceeded

input:

230 470
212 98
107 123
116 72
158 83
135 111
78 123
221 217
214 203
28 221
229 3
111 127
128 13
125 116
180 78
175 191
182 99
194 6
12 83
209 29
169 129
192 208
145 38
33 86
104 85
145 82
38 82
193 153
109 41
199 194
89 72
161 227
36 177
13 141
173 110
212 77
155 81
87 82
104 172
148 182
170 222
68 ...

output:

? 6 9
? 9 52
? 6 9
? 9 85
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
? 6 9
? 9 52
?...

result: