QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#662234 | #7503. Too Many Edges | ivyoruska# | WA | 1ms | 4816kb | C++14 | 1.7kb | 2024-10-20 22:06:16 | 2024-10-20 22:06:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int N = 5e4 + 10;
const int M = 1e5 + 10;
const int inf = 0x3f3f3f3f;
int n, m;
int e[M];
struct edge {
int idx;
int v;
};
vector<edge> gra[N];
map<pair<int, int>, int> mp;
int lp;
bool longestpath() {
vector<int> in_degree(n + 1);
vector<pair<int, int> > dp(n + 1, {0, inf}); // 长度,前导节点
for (int i = 1; i <= n; i++) {
for (auto [idx, v] : gra[i]) {
if (e[idx]) continue;
in_degree[v]++;
}
}
queue<int> qu;
for (int i = 1; i <= n; i++) {
if (!in_degree[i]) qu.push(i);
}
int mx = 0;
int mxu = 0;
while (qu.size()) {
int u = qu.front();
qu.pop();
if (!dp[u].first) dp[u] = {1, 0};
if (dp[u].first > mx) mx = dp[u].first, mxu = u;
for (auto [idx, v] : gra[u]) {
if (e[idx]) continue;
in_degree[v]--;
if (dp[v].first < dp[u].first + 1) dp[v] = {dp[u].first + 1, u};
if (!in_degree[v]) qu.push(v);
}
}
lp = mx;
int op = 1;
for (int u = mxu; dp[u].second; u = dp[u].second) {
cout << "? " << dp[u].second << ' ' << u << endl;
cin >> op;
if (!op) {
e[mp[{dp[u].second, u}]] = 1;
return true;
}
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
gra[u].push_back({i, v});
mp[{u, v}] = i;
}
while (longestpath())
;
cout << "! " << lp << endl;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 4816kb
input:
5 5 1 2 1 3 2 5 3 4 4 5 1 0 1 1
output:
? 4 5 ? 3 4 ? 2 5 ? 1 2 ! 3
result:
wrong answer The answer is incorrect