QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#540677#7860. Graph of Maximum Degree 3RepeaterWA 0ms3812kbC++202.7kb2024-08-31 17:40:442024-08-31 17:40:47

Judging History

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

  • [2024-08-31 17:40:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3812kb
  • [2024-08-31 17:40:44]
  • 提交

answer

#include <bits/stdc++.h>

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

    int n, m;
    std::cin >> n >> m;

    std::vector<std::vector<std::pair<int, int>>> adj(n);
    for (int i = 0; i < m; i++) {
        int u, v, w;
        std::cin >> u >> v >> w;
        u--, v--;

        adj[u].emplace_back(v, w);
        adj[v].emplace_back(u, w);
    }

    int ans = n, ans2 = 0, ans3 = 0;
    std::vector<int> cnt(n), cnt2(n);

    auto check = [&](int x, int y) -> bool {
        for (auto [j, c] : adj[x]) cnt2[j]++;
        bool ok = cnt2[y] == 2;
        for (auto [j, c] : adj[x]) cnt2[j]--;

        return ok;
    };

    for (int i = 0; i < n; i++) {
        int x = -1, y = -1, z = -1;
        int cx = -1, cy = -1, cz = -1;
        for (auto [j, c] : adj[i]) {
            cnt[j]++;
            if(cnt[j] == 1)
            {
                if(x == -1) x = j, cx = c;
                else if(y == -1) y = j, cy = c;
                else if(z == -1) z = j, cz = c;
            }
            if(cnt[j] == 2)
                ans3++;
        }

        if(z == -1)
        {
            if(cnt[x] == 2)
                std::swap(x, y), std::swap(cx, cy);
            for(auto [j, c] : adj[x])
                if(j == y && c != cx)
                    ans3++;

            for(auto [j, c] : adj[y])
                if(check(j, x))
                    ans2++;

            cnt[x] = 0, cnt[y] = 0;
        }
        else
        {
            std::array<int, 2> tmp{0, 0};
            int a = 0, b = 0;
            if(cx == 1) a++;
            if(cy == 1) a++;
            if(cz == 1) a++;
            if(a == 2) tmp[0]++;
            else tmp[1]++;

            a = 0, b = 0;
            for (auto [j, c] : adj[x]) 
            {
                cnt[j]++;
                if(c == 1) a++;
                else b++;
            }
            if(a == 2 && b == 1) tmp[0]++;
            else tmp[1]++;

            a = 0, b = 0;
            for (auto [j, c] : adj[x]) 
            {
                cnt[j]++;
                if(c == 1) a++;
                else b++;
            }
            if(a == 2 && b == 1) tmp[0]++;
            else tmp[1]++;

            a = 0, b = 0;
            for (auto [j, c] : adj[x]) 
            {
                cnt[j]++;
                if(c == 1) a++;
                else b++;
            }
            if(a == 2 && b == 1) tmp[0]++;
            else tmp[1]++;

            if(cnt[x] == cnt[y] && cnt[x] == cnt[z] && cnt[x] == 3 && tmp[0] == 2 && tmp[1] == 2)
                ans2++;

            cnt[x] = 0, cnt[y] = 0, cnt[z] = 0;
        }
    }

    std::cout << ans + ans3 / 2 + ans2 / 4 << "\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3812kb

input:

4 6
1 2 0
2 3 0
3 4 0
1 4 1
2 4 1
1 3 1

output:

4

result:

wrong answer 1st numbers differ - expected: '5', found: '4'