QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#668920#8333. Gifthuan_yp#WA 2ms9160kbC++141.3kb2024-10-23 16:36:022024-10-23 16:37:22

Judging History

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

  • [2024-10-23 16:37:22]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9160kb
  • [2024-10-23 16:36:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
vector<int> e[N];
int fa[N], deg[N], cnt[10];
vector<int> cycle;
void dfs(int u){
    for(auto v:e[u]){
        if(v==fa[u])continue;
        if(fa[v]!=-1){
            int x=u;
            cycle.push_back(v);
            while(x!=v){
                // cerr << "W:" << x << '\n';
                cycle.push_back(x);
                x=fa[x];
                // cerr << x << '\n';
                break;
            }
            continue;
        }
        fa[v]=u;
        dfs(v);
    }
}
int main(){
    int n;
    cin>>n;
    memset(fa,-1,sizeof(fa));
    fa[1]=0;
    for(int i=1;i<=n;i++){
        int x,y;cin>>x>>y;
        deg[x]++,deg[y]++;
        e[x].push_back(y),e[y].push_back(x);
    }
    dfs(1);
    long long ans=0;
    for(int i=1;i<=n;i++){
        cnt[deg[i]]++;
    }
    cycle.push_back(cycle[0]);
    for(int i=0; i<cycle.size()-1; i++){
        int u=cycle[i], v=cycle[i+1];
        cnt[deg[u]]--, cnt[deg[v]]--;
        cnt[deg[u]-1]++, cnt[deg[v]-1]++;
        if(cnt[5]==0){
            ans += cnt[3] + cnt[2] + cnt[1];
        }
        cnt[deg[u]-1]--, cnt[deg[v]-1]--;
        cnt[deg[u]]++, cnt[deg[v]]++;
        
    }
    cout << ans << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9036kb

input:

6
1 2
1 3
1 4
1 5
1 6
2 3

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 9160kb

input:

3
1 3
3 2
2 1

output:

12

result:

wrong answer 1st numbers differ - expected: '9', found: '12'