QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#721524#6765. Don't Really Like How The Story Ends333zhanWA 67ms3536kbC++201.8kb2024-11-07 16:18:532024-11-07 16:18:54

Judging History

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

  • [2024-11-07 16:18:54]
  • 评测
  • 测评结果:WA
  • 用时:67ms
  • 内存:3536kb
  • [2024-11-07 16:18:53]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long

using namespace std;

void solve () {
	int n, m;
	cin >> n >> m;
	
    vector <vector <int>> e (n);
    for (int i = 0; i < m; i ++) {
        int x, y;
        cin >> x >> y;
        x --; y --;

        if (x == y) {
            continue;
        }
        if (x > y) {
            swap (x, y);
        }
        e[x].push_back (y);
    }

    for (int i = 0; i < n; i ++) {
        sort (e[i].begin (), e[i].end ());
        e[i].erase (unique (e[i].begin (), e[i].end ()), e[i].end ());
    }

    vector <int> fa (n, -1);
    int ans = 0;
    int now;

    vector <int> nfa;

    auto dfs = [&](auto &&self, int x) -> void {
        now = x;
        for (auto y : e[x]) {
            fa[y] = x;            
        }
        const int N = e[x].size ();
        for (int i = 0; i < N; i ++) {
            int y = e[x][i];
            if (y <= now) {
                continue;
            }
            if (i < N - 1) {
                nfa.push_back (x);
            }
            if (y == now + 1) {
                self (self, y);
                nfa.pop_back ();
                continue;
            }
            nfa.push_back (x);
            while (y > now + 1) {
                ans ++;
                self (self, now + 1);
            }
            nfa.pop_back ();
        }
        if (x == n - 1) {
            return;
        }
        if (now == x) {
            if (fa[x + 1] == -1 || (nfa.size () && nfa.back () != fa[x + 1])) {
                ans ++;
            }
            self (self, x + 1);
        }
    };
    dfs (dfs, 0);

    cout << ans << '\n';
}

signed main () {
    ios::sync_with_stdio (false);
    cin.tie (nullptr);

    int T = 1;
    cin >> T;

    while (T --) {
        solve ();
    }

    return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 67ms
memory: 3536kb

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
1
1
1
0
0
2
0
2
0
1
0
0
3
0
0
0
2
1
1
1
0
0
0
2
0
2
1
3
0
2
0
3
1
2
1
0
0
1
2
0
2
0
1
2
0
0
2
0
0
0
1
0
3
0
1
0
0
1
0
0
3
2
0
0
0
1
0
2
3
0
1
1
1
1
0
0
2
1
3
0
1
2
0
0
0
3
0
0
3
1
0
2
0
0
0
1
0
1
0
0
0
0
4
0
0
0
0
0
0
2
0
2
0
0
1
1
0
0
2
0
1
0
0
0
2
0
1
2
1
0
0
0
1
0
0
1
1
1
0
0
0
...

result:

wrong answer 107th lines differ - expected: '0', found: '1'