QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#384807#7860. Graph of Maximum Degree 3iwewWA 1ms3764kbC++203.1kb2024-04-10 12:44:452024-04-10 12:44:45

Judging History

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

  • [2024-04-10 12:44:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3764kb
  • [2024-04-10 12:44:45]
  • 提交

answer

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

typedef long long ll;

const int N = 1e5 + 10, mod = 998244353;

vector<pair<int, int>> adj[N];

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

    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i ++ ) {
        int u, v, c;
        cin >> u >> v >> c;
        adj[u].push_back({v, c});
        adj[v].push_back({u, c});
    }

    vector<ll> f(5, 0);
    for(int u = 1; u <= n; u ++ ) {
        set<pair<int, int>> s;
        for(auto [v, c] : adj[u]) {
            s.insert({v, c});
        }
        for(auto [v, c] : s) {
            if(!s.count({v, !c})) {
                f[1] ++ ;
            }
        }
    }
    f[0] = n, f[1] = 1ll * n * (n - 1) / 2 - f[1] / 2;
    
    for(int u = 1; u <= n; u ++ ) {
        multiset<pair<int, int>> s;
        for(auto [v, c] : adj[u]) {
            s.insert({v, c});
        }
        vector<int> arr;
        for(auto [v, c] : adj[u]) {
            if(s.count({v, !c})) {
                arr.push_back(v);
            }
        }
        for(auto v : arr) {
            for(auto [q, c] : adj[v]) {
                if(s.count({q, !c})) {
                    f[2] ++ ;
                }
            }
        }
    }
    f[2] = f[2] / 4;

    for(int u = 1; u <= n; u ++ ) {
        for(auto [v, c] : adj[u]) {
            multiset<pair<int, int>> su, sv;
            for(auto [q, cc] : adj[u]) {
                su.insert({q, cc});
            }
            for(auto [q, cc] : adj[v]) {
                sv.insert({q, cc});
            }

            for(auto [p, _] : adj[u]) {
                for(auto [q, __] : adj[v]) {
                    if(p != v && p != q && q != u) {
                        for(auto [tmpv, tmpc] : adj[p]) {
                            if(tmpv == q && tmpc == 1 && c == 0) {
                                if(su.count({p, 0}) && su.count({p, 1}) && sv.count({q, 0}) && sv.count({q, 1})) {
                                    f[3] ++ ;
                                }
                                if(su.count({p, 1}) && su.count({q, 0}) && sv.count({p, 0}) && sv.count({q, 1})) {
                                    f[4] ++ ;
                                }
                            } else if(tmpv == q && tmpc == 0 && c == 1) {
                                if(su.count({p, 0}) && su.count({p, 1}) && sv.count({q, 0}) && sv.count({q, 1})) {
                                    f[3] ++ ;
                                }
                                if(su.count({p, 0}) && su.count({q, 1}) && sv.count({p, 1}) && sv.count({q, 0})) {
                                    f[4] ++ ;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    f[3] = f[3] / 4, f[4] = f[4] / 4;

    ll ans = 0;
    for(int i = 0; i < 5; i ++ ) {
        // cout << f[i] << ' ';
        ans = (ans + f[i] % mod) % mod;
    }
    // cout << '\n';
    cout << ans << '\n';

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3548kb

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: 0
Accepted
time: 0ms
memory: 3764kb

input:

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

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

20 28
9 6 1
9 6 0
3 8 0
8 4 0
3 8 1
3 4 1
2 13 0
13 1 0
19 1 0
2 1 1
2 19 1
13 19 1
14 15 1
14 15 0
7 12 0
12 17 0
20 17 0
7 17 1
7 20 1
12 20 1
16 18 0
18 10 0
5 10 0
16 10 1
16 5 1
18 5 1
4 6 0
9 11 0

output:

192

result:

wrong answer 1st numbers differ - expected: '27', found: '192'