QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#657714#6765. Don't Really Like How The Story EndsCangShuV#WA 89ms8324kbC++231.3kb2024-10-19 15:19:242024-10-19 15:19:26

Judging History

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

  • [2024-10-19 15:19:26]
  • 评测
  • 测评结果:WA
  • 用时:89ms
  • 内存:8324kb
  • [2024-10-19 15:19:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
set<int> g[N];
void add(int f, int t) {
    g[f].insert(t);
    g[t].insert(f);
}

void clr(int n) {
    n += 2;
    for (int i = 0; i <= n; ++i) {
        g[i].clear();
    }
}

int res = 0;
int st[N];
int n, m;

// set<int> stt;
void dfs(int u, int go) {
    st[u] = 1;

    int acc = 0;
    for (auto &it : g[u]) {
        if (!st[it]) {
            if (it == go) {
                dfs(go, go + 1);
            } else
                acc = 1;
        }
    }
    if (!st[go])
        if (acc) {
            add(u, go);
            ++res;
            dfs(go, go + 1);
        }
    if (u == 1) {
        for (int i = 1; i <= n; ++i) {
            if (!st[i]) {
                if (g[1].find(i) == g[1].end()) {
                    add(1, i);
                    ++res;
                }
                dfs(i, i + 1);
            }
        }
    }
}

int a, b;
void solve() {
    cin >> n >> m;
    clr(n);

    res = 0;
    for (int i = 1; i <= n; ++i)
        st[i] = 0;
    for (int i = 1; i <= m; ++i) {
        cin >> a >> b;
        add(a, b);
    }
    dfs(1, 2);
    cout << res << '\n';
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;
    while (n--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

0
2
1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 89ms
memory: 8292kb

input:

117747
3 7
2 1
3 3
1 3
1 1
3 2
1 1
3 1
4 8
2 3
4 3
3 2
4 2
1 3
2 1
4 3
2 4
3 4
2 3
2 2
3 3
1 1
2 5
1 1
2 2
2 2
1 2
2 2
3 7
2 1
1 2
3 3
3 2
1 2
3 3
3 2
4 5
1 2
3 3
4 4
1 4
2 1
3 1
3 2
1 3
1 1
1 1
1 1
1 6
1 1
1 1
1 1
1 1
1 1
1 1
5 4
2 1
2 5
1 3
3 2
4 7
1 1
2 4
3 2
1 1
1 1
4 2
2 3
5 8
3 3
2 2
4 2
1 4
1...

output:

0
0
1
0
0
1
1
0
0
2
2
1
0
0
3
0
2
0
1
0
1
3
0
0
0
2
1
1
1
0
0
0
2
0
3
1
4
0
1
0
4
1
2
1
0
0
1
2
0
3
0
1
2
0
0
2
0
0
0
1
0
3
0
2
0
0
1
1
0
3
2
0
0
0
1
0
2
4
0
1
1
1
1
0
0
3
1
3
0
1
2
0
0
0
4
0
0
3
1
0
2
0
0
0
1
0
0
0
0
0
0
4
0
0
0
0
0
0
2
0
1
0
0
1
1
0
0
2
0
1
0
0
0
3
1
1
2
1
0
1
0
1
0
0
1
1
1
0
0
0
...

result:

wrong answer 10th lines differ - expected: '1', found: '2'