QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627094#7860. Graph of Maximum Degree 3LeoTengWA 0ms12048kbC++142.2kb2024-10-10 14:43:122024-10-10 14:43:15

Judging History

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

  • [2024-10-10 14:43:15]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:12048kb
  • [2024-10-10 14:43:12]
  • 提交

answer

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

#define rep(i, a, b) for(int i = a; i < (b) ; ++i)
#define all(x) begin(x) , end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int , int> pii;
typedef vector<int> vi;
const int MAXN = 2e5+5;
int deg[2][MAXN],ded[MAXN];
vector<pii>adj[MAXN];
int par[2][MAXN],szz[2][MAXN];
int find(int x,int c){
    if(par[c][x] == x)return x;
    return par[c][x] = find(par[c][x],c);
}
void unite(int a,int b,int c){
    a = find(a,c);
    b = find(b,c);
    if(a==b)return;
    par[c][a] = b;
    szz[c][b] += szz[c][a];
}
map<pii,int>mp[2];
int main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    int n,m;
    cin>>n>>m;
    ll ans = n;
    for(int i=1;i<=n;i++){
        par[0][i] = par[1][i] = i;
        szz[0][i] = szz[1][i] = 1;
    }
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        if(a>b)swap(a,b);
        adj[a].push_back({b,c});
        adj[b].push_back({a,c});
        deg[c][a]++;
        deg[c][b]++;
        mp[c][{a,b}]++;
    }
    for(auto [x,y]:mp[0]){
        if(mp[1][x])ans++;
    }
    queue<int>q;
    for(int i=1;i<=n;i++){
        if(!deg[0][i] || !deg[1][i]){
            q.push(i);
            ded[i] = 1;
        }
    }
    while(!q.empty()){
        int v = q.front();
        q.pop();
        for(auto [x,c]:adj[v]){
            if(!ded[x])continue;
            deg[c][x]--;
            if(!deg[c][x]){
                ded[x] = 1;
                q.push(x);
            }
        }
    }
    for(int i=1;i<=n;i++){
            if(ded[i])continue;
            for(auto [j,c]:adj[i]){
                if(ded[j])continue;
                if(c==1)continue;
                if(i>j)continue;
                for(auto [k,c0]:adj[j]){
                    if(ded[k])continue;
                    if(c0==1)continue;
                    if(j>k)continue;
                    bool ok = 0;
                    if(mp[1][{i,j}] && mp[1][{i,k}])ok = 1;
                    if(mp[1][{i,k}] && mp[1][{j,k}])ok = 1;
                    ans += ok;
                }
            }
    }



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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 11784kb

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'