QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#300706#7860. Graph of Maximum Degree 3pengpeng_fudanWA 3ms13708kbC++142.1kb2024-01-08 17:25:252024-01-08 17:25:26

Judging History

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

  • [2024-01-08 17:25:26]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:13708kb
  • [2024-01-08 17:25:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
using ull=unsigned long long;
using ll=long long;
unordered_map<int,int> mp[100010];
const ll mod=998244353;
int ct[100010];
int le[100010],re[100010];
vector<pair<int,int>> ve[100010];
bool flag[100010];
int sz=0,zo=0,on=0;
int mq=0;
void dfs(int u){
    sz++;
    flag[u]=1;
    for(auto i:ve[u]){
        if(mp[u][i.first]==3)  mq=1;
        if(i.second==0) zo++;
        else on++;
        if(flag[i.first])   continue;
        //flag[i.first]=1;
        dfs(i.first);
    }
}
void solve() {
    int n,m;
    cin>>n>>m;
    ll ans=n;
    for(int i=1,u,v,w;i<=m;i++){
        cin>>u>>v>>w;
        ve[u].push_back({v,w});
        ve[v].push_back({u,w});
        if(!mp[u][v])   mp[u][v]=w+1;
        else{
            mp[u][v]=3;
            ans=(ans+1)%mod;
        }
        swap(u,v);
        if(!mp[u][v])   mp[u][v]=w+1;
        else{
            mp[u][v]=3;
            //ans++;
        }
    }
    ll mzq=0;
    for(int i=1;i<=n;i++){
        for(auto j:mp[i]){
            if(j.second==3){
                if(mp[i].size()==2&&mp[j.first].size()==2){
                    int lz=0,rz=0;
                    int lj=0,lq=0;
                    for(auto mz:mp[i]){
                        if(mz.first!=j.first)  lj=mz.first;
                        lz+=mz.second;
                    }
                    for(auto mz:mp[j.first]){
                        if(mz.first!=i)  lq=mz.first;
                        rz+=mz.second;     
                    } 
                    if(lz+rz==9&&lj==lq){
                        mzq++;
                        //cout<<i<<' '<<j.first<<'\n';
                    }          
                }
            }
        }
    }
    ans=(ans+mzq/2)%mod;
    for(int i=1;i<=n;i++){
        sz=zo=on=mq=0;
        if(!flag[i])    dfs(i);
        //cout<<sz<<' '<<zo<<' '<<on<<'\n';
        if(sz==4&&zo==6&&on==6&&mq) ans=(ans+1)%mod;
    }
    cout<<ans%mod<<'\n';
}
signed main() {
    ios::sync_with_stdio(0),cin.tie(0);
    int _ = 1;
    //cin >> _;
    while(_--) solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 11612kb

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: 3ms
memory: 13708kb

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'