QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#662234#7503. Too Many Edgesivyoruska#WA 1ms4816kbC++141.7kb2024-10-20 22:06:162024-10-20 22:06:17

Judging History

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

  • [2024-10-20 22:06:17]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4816kb
  • [2024-10-20 22:06:16]
  • 提交

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