QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#658007#8333. Giftyiyiyi#WA 3ms16840kbC++142.1kb2024-10-19 15:58:012024-10-19 15:58:01

Judging History

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

  • [2024-10-19 15:58:01]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:16840kb
  • [2024-10-19 15:58:01]
  • 提交

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(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: 5828kb

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: 0
Accepted
time: 1ms
memory: 7896kb

input:

3
1 3
3 2
2 1

output:

9

result:

ok 1 number(s): "9"

Test #3:

score: 0
Accepted
time: 0ms
memory: 8144kb

input:

2332
1648 909
1676 2122
1644 1981
1106 1131
1785 239
223 618
335 1662
424 1775
889 1684
1589 52
1406 1747
1600 302
790 2056
1742 464
1706 541
1145 779
2316 833
1645 1439
859 438
1337 136
746 1565
436 1730
2079 2145
1583 1940
917 1549
1863 507
1266 367
1890 2230
13 2113
492 2109
120 1122
815 1111
134...

output:

5438224

result:

ok 1 number(s): "5438224"

Test #4:

score: -100
Wrong Answer
time: 3ms
memory: 16840kb

input:

100000
46198 33056
80285 88339
88963 925
43203 66233
13618 35880
19864 76475
90021 73072
3202 63653
41571 83067
22067 98768
10753 16653
32856 85797
3483 2064
46659 9486
23290 82179
97966 23617
81566 7334
81774 76138
10959 75816
93471 12058
97260 66262
85541 78476
67864 87220
8607 52245
38957 67603
7...

output:

1410065408

result:

wrong answer 1st numbers differ - expected: '10000000000', found: '1410065408'