QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#232224 | #7503. Too Many Edges | OAleksa | WA | 1ms | 4680kb | C++14 | 1.7kb | 2023-10-30 05:34:35 | 2023-10-30 05:34:36 |
Judging History
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] = par[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: 1ms
memory: 4612kb
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
Wrong Answer
time: 0ms
memory: 4680kb
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 ? 52 85 ? 85 104 ? 2 32 ? 32 49 ? 21 111 ? 111 135 ? 6 17 ? 35 49 ? 49 58 ? 104 108 ? 62 135 ? 135 167 ? 52 108 ? 108 110 ? 52 85 ? 85 152 ? 21 111 ? 111 127 ? 127 176 ? 17 69 ? 69 110 ? 23 26 ? 35 49 ? 49 55 ? 12 58 ? 2 58 ? 104 152 ? 152 194 ? 62 135 ? 135 198 ? 198 201 ?...
result:
wrong answer The answer is incorrect