QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#705144#6526. CanvasllleiWA 3ms11796kbC++204.2kb2024-11-02 22:18:022024-11-02 22:18:27

Judging History

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

  • [2024-11-02 22:18:27]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:11796kb
  • [2024-11-02 22:18:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
vector<int> e[N], num[N];
bool vis[N], vis1[N];
int n, m;
int ans[N];
int s[N];
int d[N];
vector<int> ans2, ans3;
void dfs(int now) {
    // cout<<now<<endl;
    ans[now] = 2;
    vis[now] = 1;
    int tmp = e[now].size();
    for (int i = 0; i < tmp; i++)
        if (!vis[e[now][i]]) {
            ans2.push_back(num[now][i]);
            dfs(e[now][i]);
        } else
            ans3.push_back(num[now][i]);
    return;
}
bool vis2[N];
bool flag;
queue<int> que;
int ifdag[N];
void dfs1(int now) {
    if (ifdag[now])
        return;
    vis2[now] = 1;
    que.push(now);
    int tmp = e[now].size();
    for (int i = 0; i < tmp; i++) {
        if (!vis2[e[now][i]]) {
            dfs1(e[now][i]);
            if (flag)
                return;
        } else {
            flag = true;
            return;
        }
    }
}
int main() {
    int T;
    cin >> T;
    while (T--) {
        cin >> n >> m;
        ans2.clear();
        ans3.clear();
        for (int i = 1; i <= n; i++) {
            vis[i] = 0;
            vis1[i] = 0;
            ans[i] = 0;
            vis2[i] = 0;
            s[i] = 0;
            d[i] = 0;
            e[i].clear();
            num[i].clear();
            ifdag[i] = 0;
        }
        for (int i = 1; i <= m; i++) {
            int l, x, r, y;
            cin >> l >> x >> r >> y;
            if (x > y) {
                swap(l, r);
                swap(x, y);
            }
            vis1[l] = vis1[r] = 1;
            if (x == 2 && y == 2) {
                ans[l] = ans[r] = 2;
                s[l] = 1;
                s[r] = 1;
                ans2.push_back(i);
            }
            if (x == 1 && y == 2) {
                e[l].push_back(r);
                num[l].push_back(i);
                d[r]++;
            }
            if (x == 1 && y == 1)
                ans3.push_back(i);
        }
        for (int i = 1; i <= n; i++) {
            if (s[i] && !vis[i] && vis1[i])
                dfs(i);
        }
        for (int i = 1; i <= n; i++)
            if (d[i] == 0 && !vis[i] && vis1[i]) {
                dfs(i);
                ans[i] = 1;
            }
        vector<int> dfn(n + 1), low(n + 1), bel(n + 1);
        int cur = 0;
        int cnt = 0;
        vector<int> stk;

        auto dfss = [&](auto &&self, int u) -> void {
            dfn[u] = low[u] = ++cur;
            stk.push_back(u);

            for (auto v : e[u]) {
                if (dfn[v] == -1) {
                    self(self, v);
                    low[u] = min(low[u], low[v]);
                } else if (bel[v] == -1) {
                    low[u] = min(low[u], dfn[v]);
                }
            }

            if (dfn[u] == low[u]) {
                int v;
                ++cnt;
                do {
                    v = stk.back();
                    bel[v] = cnt;
                    stk.pop_back();
                } while (v != u);
            }
        };

        for (int i = 1; i <= n; ++i) {
            if (dfn[i] == 0) {
                dfss(dfss, i);
            }
        }

        vector<int> dd(cnt + 1);

        for (int i = 1; i <= n; ++i) {
            for (int v : e[i]) {
                if (bel[i] != bel[v]) {
                    dd[bel[v]]++;
                }
            }
        }

        for (int i = 1; i <= n; i++)
            if (!vis[i] && vis1[i]) {
                flag = false;
                if (dd[bel[i]] == 0) {
                    dfs(i);
                    ans[i] = 1;
                }
            }
        for (int i = 1; i <= n; i++)
            if (vis1[i])
                ans[i] = max(ans[i], 1);
        int ans1 = 0;
        for (int i = 1; i <= n; i++) {
            ans1 += ans[i];
            // cout<<ans[i]<<' ';
        }
        cout << ans1 << endl;
        int tmp = ans3.size();
        for (int i = 0; i < tmp; i++)
            cout << ans3[i] << ' ';
        tmp = ans2.size();
        for (int i = tmp - 1; i >= 0; i--)
            cout << ans2[i] << ' ';
        cout << endl;
    }
    return 0;
}

详细

Test #1:

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

input:

2
4 4
1 1 2 2
3 2 4 1
1 2 3 2
2 1 4 1
4 2
3 2 4 1
1 2 3 1

output:

7
4 2 1 3 
5
2 1 

result:

ok Correct. (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 11784kb

input:

1
10 13
1 1 2 2
2 1 3 2
1 2 3 1
3 1 4 2
4 1 5 2
5 1 6 2
4 2 6 1
7 1 8 2
8 1 9 2
7 2 9 1
5 2 9 1
8 2 10 2
1 1 10 1

output:

17
13 8 5 7 6 11 10 9 12 

result:

wrong output format Unexpected end of file - int32 expected (test case 1)