QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#691901#8333. GiftcharmyyWA 0ms10556kbC++141.0kb2024-10-31 13:21:392024-10-31 13:21:39

Judging History

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

  • [2024-10-31 13:21:39]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:10556kb
  • [2024-10-31 13:21:39]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
#define int long long
typedef pair<int,int> pii;

const int N = 2e5+5;

int n;
vector<int> e[N];
int du[N],du1[N];

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	cin>>n;
	for(int i=1;i<=n;i++){
		int x,y;
		cin>>x>>y;
		e[x].push_back(y);
		e[y].push_back(x);
		du[x]++,du[y]++;
		du1[x]++,du1[y]++;
	}
	queue<int> q;
	set<int> s;
	int sum=0;
	for(int i=1;i<=n;i++){
		if(du1[i]==1){
			q.push(i);
		}
		if(du1[i]>=4){
			sum++;
		}
		if(du1[i]==5){
			s.insert(i);
		}
	}
	
	while(!q.empty()){
		int t=q.front();
		q.pop();
		
		for(auto v:e[t]){
			if(du1[v]!=1){
				du1[v]--;
				if(du1[v]==1){
					q.push(v);
				}
			}
		}
	}
	
	set<int> se;
	for(int i=1;i<=n;i++){
		if(du1[i]!=1){
			se.insert(i);
		}
	}
	int ans=0;
	for(auto i:se){
		for(auto j:e[i]){
			if(se.count(j)!=0&&se.size()-s.count(j)!=0){
				ans+=n-sum;
				if(du[i]==4) ans++;
				if(du[j]==4) ans++;
			}
		}
	}
	cout<<ans/2<<"\n";
	
	return 0;	

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 10556kb

input:

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

output:

15

result:

wrong answer 1st numbers differ - expected: '10', found: '15'