QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#711943#8333. GiftsyzWA 22ms17200kbC++231.3kb2024-11-05 14:04:112024-11-05 14:04:12

Judging History

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

  • [2024-11-05 14:04:12]
  • 评测
  • 测评结果:WA
  • 用时:22ms
  • 内存:17200kb
  • [2024-11-05 14:04:11]
  • 提交

answer

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

vector<int> adj[100001];
int st[100001], ins[100001];
int fa[100001];
int ic[100001];
int cyc = 0;
void dfs(int u, int p) {
    st[u] = ins[u] = 1;
    for (auto x : adj[u]) {
        if (x == p) continue;
        fa[x] = u;
        if (!st[x]) dfs(x, u);
        else if (ins[x]) {
            for (int k = u;k != x;k = fa[k]) {
                ic[k] = 1, ++ cyc;
            }
            ic[x] = 1;
            ++ cyc;
        }
    }
    ins[u] = 0;
}
int d[100001];
int main() {
    cin.tie(0) -> sync_with_stdio(0);
    int N;cin >> N;
    for (int i = 1;i <= N;i ++ ) {
        int x, y;cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
        ++ d[x];
        ++ d[y];
    }
    dfs(1, 0);
    int c = 0;
    int p = 0;
    for (int i = 1;i <= N;i ++ ) 
        if (d[i] == 5) ++ c, p = i;
    int ans = 0;

    vector<bool> ok(N + 1);
    for (auto x : adj[p]) ok[x] = 1;

    for (int i = 1;i <= N;i ++ ) 
        if (d[i] <= 3) 
            ans += (c == 2 ? 1 : (c == 1 ? 2 : cyc));
        else if (d[i] == 4) {
            if (ic[i]) {
                ans += (c == 2 ? 0 : (c == 1 ? (ok[i] ? 1 : 0) : 2));
            }
        } 
    cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
1 2
1 3
1 4
1 5
1 6
2 3

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3540kb

input:

3
1 3
3 2
2 1

output:

9

result:

ok 1 number(s): "9"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3864kb

input:

2332
1648 909
1676 2122
1644 1981
1106 1131
1785 239
223 618
335 1662
424 1775
889 1684
1589 52
1406 1747
1600 302
790 2056
1742 464
1706 541
1145 779
2316 833
1645 1439
859 438
1337 136
746 1565
436 1730
2079 2145
1583 1940
917 1549
1863 507
1266 367
1890 2230
13 2113
492 2109
120 1122
815 1111
134...

output:

5438224

result:

ok 1 number(s): "5438224"

Test #4:

score: -100
Wrong Answer
time: 22ms
memory: 17200kb

input:

100000
46198 33056
80285 88339
88963 925
43203 66233
13618 35880
19864 76475
90021 73072
3202 63653
41571 83067
22067 98768
10753 16653
32856 85797
3483 2064
46659 9486
23290 82179
97966 23617
81566 7334
81774 76138
10959 75816
93471 12058
97260 66262
85541 78476
67864 87220
8607 52245
38957 67603
7...

output:

1410065408

result:

wrong answer 1st numbers differ - expected: '10000000000', found: '1410065408'