QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#658003#8333. Giftyiyiyi#WA 1ms7848kbC++142.1kb2024-10-19 15:57:262024-10-19 15:57:28

Judging History

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

  • [2024-10-19 15:57:28]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7848kb
  • [2024-10-19 15:57:26]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define re register
#define N 1000012
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,x,n) for(int i = x; i <= n; i++)
using namespace std;

inline int read(){
	int x=0,w=0;char ch=getchar();
	while (!isdigit(ch))w|=ch=='-',ch=getchar();
	while (isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return w?-x:x;
}
const int maxn = 2e5 + 5;
int cnt = 1, ver[maxn << 1], nxt[maxn << 1], head[maxn], deg[maxn];
void add(int x, int y) {
	cnt++;
	ver[cnt] = y;
	nxt[cnt] = head[x];
	head[x] = cnt;
	deg[x]++;
}

bool vis[maxn];
int top;
pii st[maxn];
struct node {
	int x, y;
}cir[maxn];
int tot;
bool flag = 0;
int is[maxn];
void dfs(int x, int fa) {
	if(flag) return;
	if(vis[x]) {
		while(st[top].first != x) {
			cir[++tot] = {st[top].first, ver[st[top].second]};	
			is[st[top].first] = 1;
			--top;
		}
		cir[++tot] = {st[top].first, ver[st[top].second]};
		is[st[top].first] = 1;
		--top;
		flag = 1;
		
		return;
	}
	vis[x] = 1;
	for(int i = head[x]; i; i = nxt[i]) {
		if(ver[i] == (fa ^ 1)) continue;
		st[++top] = {x, i};
		dfs(ver[i], i);
		if(flag) return;
		--top;
	}
}

int num[10];

void del(int x) {
	if(deg[x] == 5 || deg[x] == 4) {
		num[deg[x]]--;
		num[deg[x] - 1]++;
	}
}
void redel(int x) {
	if(deg[x] == 5 || deg[x] == 4) {
		num[deg[x]]++;
		num[deg[x] - 1]--;
	}
}
signed main(){
	int n = read();
	rep(i,1,n) {
		int x = read(), y = read();
		add(x, y); add(y, x);
	}
	dfs(1, 0);
	rep(i,1,n) {
		if(!is[i] && deg[i] > 4) {
			puts("0");
			return 0;
		} 
		if(deg[i] > 5) {
			puts("0");
			return 0;
		}
		if(is[i] && deg[i] == 5) {
			num[5]++;
		}
		if(is[i] && deg[i] == 4) {
			num[4]++;
		}
		if(deg[i] <= 3) {
			num[3]++;
		}
	}
//	printf("%lld %lld %lld\n", num[3], num[4], num[5]);
	int ans = 0;
	rep(i,1,tot) {
		int x = cir[i].x, y = cir[i].y;
//		printf("%lld %lld\n", x, y);
		del(x); del(y);
		if(!num[5]) ans += num[3];
		redel(x); redel(y);
	}
	printf("%lld\n", ans);
}

详细

Test #1:

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

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

input:

3
1 3
3 2
2 1

output:

6

result:

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