QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#713399#8333. GiftArvin#WA 1ms5532kbC++201.2kb2024-11-05 19:13:512024-11-05 19:13:52

Judging History

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

  • [2024-11-05 19:13:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5532kb
  • [2024-11-05 19:13:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
using ll = long long;
typedef pair<int, int> PII;
//#define int long long
const int N=1e5+5;
int d[N];
int dd[N];
vector<int> p[N];
queue<int> q;
bool vis[N];
void solve() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) {
        int u,v;
        cin>>u>>v;
        d[u]++;
        d[v]++;
        p[u].push_back(v);
        p[v].push_back(u);
    }
    for(int i=1;i<=n;i++) {
        dd[i]=d[i];
        if(d[i]==1) {
            q.push(i);
            vis[i]=1;
        }
    }
    while(!q.empty()) {
        auto t=q.front();
        q.pop();
        for(auto it : p[t]) {
            d[it]--;
            if(d[it]==1&&!vis[it]) {
                q.push(it);
                vis[it]=1;
            }
        }
    }
    int ans=0,cnt=0;
    for(int i=1;i<=n;i++) {
        if(!vis[i]) {
            ans=max(dd[i],ans);
            cnt++;
        }
    }
    // cout<<cnt<<endl;
    if(ans==5) {
        cout<<2*(n-1);
    }
    else {
        cout<<1ll*(n-1)*cnt;
    }
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    //std::cin>>T;
    while(T --) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 5532kb

input:

3
1 3
3 2
2 1

output:

6

result:

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