QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#706256#8333. GiftAnneliese#WA 23ms12212kbC++141.9kb2024-11-03 09:46:202024-11-03 09:46:20

Judging History

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

  • [2024-11-03 09:46:20]
  • 评测
  • 测评结果:WA
  • 用时:23ms
  • 内存:12212kb
  • [2024-11-03 09:46:20]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
using LL = long long;
using ll = long long;
const int N = 111111;
#define rep(i,a ,b )  for(int i = a ;i<=b;i++)
#define pre(i,a ,b )  for(int i = a ;i>=b;i--)
#define int long long
int n;
vector<int>v[100005];
vector<int> aa;
int d[100005], dd[100005];
bool st[100005];

void huan()
{
    queue<LL> q;
    for (int i = 1; i <= n; i++)
    {
        if (d[i] == 1)
        {
            q.push(i);
            st[i] = 1;
        }
    }

    while (q.size())
    {
        LL t = q.front();
        q.pop();

        for (auto x : v[t])
        {
            if (!st[x])
            {
                d[x]--;
                if (d[x] == 1)
                {
                    q.push(x);
                    st[x] = 1;
                }
            }
        }

    }
	rep(i, 1, n) {
		if (st[i] == 0) {
			aa.push_back(i);
	  }
	}
}


void solve()
{
	cin >> n;
	rep(i, 1, n) {
		int x, y; cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
		d[x]++;
		d[y]++;
	}
	int num4 = 0, num5 = 0;
	rep(i, 1, n)
	{
		if (d[i] == 4) num4++;
		else if (d[i] == 5) num5++;
		dd[i] = d[i];
	}

	huan();

	int m = aa.size();
	rep(i, 0, m - 1) aa.push_back(aa[i]);
	if (num5 == 2) {
		cout << n - num4 - num5 << endl;
		return;
	}
	else if (num5 == 1)
	{
		int ans = 0;
		rep(i, 1, m)
		{
			if (dd[aa[i]] == 5)
			{
				int n4 = num4;
				if (dd[aa[i - 1]] == 4) n4--;
				ans += n - num5 - n4;
				n4 = num4;
				if (dd[aa[i + 1]] == 4) n4--;
				ans += n - num5 - n4;
			}
		}
		cout << ans << endl;
		return;
	}
	int ans = 0;
	rep(i, 1, m)
	{
		int n4 = num4;
		if (dd[aa[i - 1]] == 4) n4--;
		if (dd[aa[i + 1]] == 4) n4--;
		ans += (n - n4);
	}
	cout << ans << endl;
	return;
}


signed main() {

	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int t = 1;
	//cin >> t ;
	while (t--) {
		solve();
	}
	return 0;

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5972kb

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

input:

3
1 3
3 2
2 1

output:

9

result:

ok 1 number(s): "9"

Test #3:

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

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: 0
Accepted
time: 23ms
memory: 12212kb

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:

10000000000

result:

ok 1 number(s): "10000000000"

Test #5:

score: 0
Accepted
time: 20ms
memory: 11456kb

input:

100000
54772 14057
70680 93042
84913 63248
79360 97774
84190 60881
31137 29439
99037 81117
38579 32074
31206 19912
70774 23067
60717 79586
83847 43306
55351 50174
32566 70092
22736 92279
55916 20029
41571 63309
33143 65579
35033 3869
50038 4275
59533 25348
53092 32698
27604 14678
6802 18226
23173 96...

output:

5017400000

result:

ok 1 number(s): "5017400000"

Test #6:

score: -100
Wrong Answer
time: 9ms
memory: 8796kb

input:

50000
26768 20197
5956 49805
44024 45008
29783 4843
7173 42904
36329 3666
1258 35410
1245 42591
41226 20145
41177 25916
38397 36431
3822 43842
414 31694
28969 33316
47036 42639
5433 1631
26813 16959
17557 18806
45146 10231
26867 24805
4416 45505
44772 32136
26263 17264
43426 20507
26630 4199
9781 89...

output:

94054

result:

wrong answer 1st numbers differ - expected: '94055', found: '94054'