QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#296772#7860. Graph of Maximum Degree 3sjw712Compile Error//C++141.8kb2024-01-03 16:08:272024-01-03 16:08:27

Judging History

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

  • [2024-01-03 16:08:27]
  • 评测
  • [2024-01-03 16:08:27]
  • 提交

answer

// 三元环计数
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int N = 1e5 + 10, M = 2e5 + 10;

int n, m;
int deg[N];
tuple<int, int, int> e[M];
vector<pii> G[N];
bool st[N][2];
ll cnt[M];

int dfs(int u, int o) {
    if (st[u][o]) return 0;
    st[u][o] = 1;
    int res = 1;
    for (auto[v, c]: G[u]) {
        if (c == o) res += dfs(v, c);
    }
    return res;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    int ans = n;
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        e[i] = {a, b, c};
        ++deg[a], ++deg[b];
    }
    set<pii> S[2];
    for (int i = 0; i < m; ++i) {
        auto&[a, b, c] = e[i];
        if (deg[a] < deg[b] || deg[a] == deg[b] && a < b) swap(a, b);
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, c);
        ans += S[c ^ 1].count({a, b});
        S[c].insert({a, b});
    }
    set<array<int, 3>> valid;
    for (int i = 1; i <= n; ++i) {
        for (auto[j, c1]: G[i]) for (auto[k, c2]: G[i]) {
            if (j == k) continue;
            array g{i, j, k};
            sort(g.begin(), g.end(), [&](int a, int b) {
                return deg[a] < deg[b] || deg[a] == deg[b] && a < b;
            });
            if (S[0].count({i, j}) + S[0].count({i, k}) + S[0].count({j, k}) >= 2 && 
                S[1].count({i, j}) + S[1].count({i, k}) + S[1].count({j, k}) >= 2) valid.insert({i, j, k}); 
        }
    }
    // for (auto a: valid) cout << a[0] << ' ' << a[1] << ' ' << a[2] << el; 
    ans += valid.size();
    for (int i = 1; i <= n; ++i) {
        if (st[i][0] || st[i][1]) continue;
        int a = dfs(i, 0), b = dfs(i, 1);
        if (a == 4 && b == 4) ++ans;
    }
    cout << ans << '\n';
}

详细

answer.code: In function ‘int dfs(int, int)’:
answer.code:20:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’
   20 |     for (auto[v, c]: G[u]) {
      |              ^
answer.code: In function ‘int main()’:
answer.code:38:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’
   38 |         auto&[a, b, c] = e[i];
      |              ^
answer.code:47:18: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’
   47 |         for (auto[j, c1]: G[i]) for (auto[k, c2]: G[i]) {
      |                  ^
answer.code:47:42: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’
   47 |         for (auto[j, c1]: G[i]) for (auto[k, c2]: G[i]) {
      |                                          ^
answer.code:49:19: error: missing template arguments before ‘g’
   49 |             array g{i, j, k};
      |                   ^
answer.code:50:18: error: ‘g’ was not declared in this scope
   50 |             sort(g.begin(), g.end(), [&](int a, int b) {
      |                  ^