QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#100577#5651. Parmigiana With Seafood5abWA 26ms7484kbC++171.3kb2023-04-26 20:24:152023-04-26 20:24:18

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-26 20:24:18]
  • 评测
  • 测评结果:WA
  • 用时:26ms
  • 内存:7484kb
  • [2023-04-26 20:24:15]
  • 提交

answer

/* name: 5651
 * author: 5ab
 * created at: 2023-04-26
 */
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long ll;
const int max_n = 100000;

int hd[max_n], des[max_n * 2], nxt[max_n * 2], par[max_n], cl[max_n], deg[max_n], cdeg[max_n], e_cnt = 0;

void add(int s, int t)
{
	des[e_cnt] = t;
	nxt[e_cnt] = hd[s];
	deg[s]++, deg[t]++;
	hd[s] = e_cnt++;
}

void dfs(int id, int fa)
{
	par[id] = fa;
	for (int p = hd[id], dst; p != -1; p = nxt[p])
	{
		dst = des[p];
		if (dst != fa)
		{
			cl[dst] = cl[id] ^ 1;
			dfs(dst, id);
		}
	}
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n;
	
	cin >> n;
	fill(hd, hd + n, -1);
	for (int i = 1, x, y; i < n; i++)
	{
		cin >> x >> y, x--, y--;
		add(x, y), add(y, x);
	}
	if (n % 2 == 0)
	{
		cout << n << endl;
		return 0;
	}
	
	dfs(n - 1, -1);
	
	int i;
	for (i = n - 1; i >= 0; i--)
	{
		if (deg[i] == 1 || cl[i] != 0)
			break;
		bool ok = true;
		for (int j = i; par[j] != -1 && cdeg[par[j]] <= 1; j = par[j])
		{
			cdeg[j]++, cdeg[par[j]]++;
			if (cdeg[par[j]] > 2 && cl[par[j]] != 1)
			{
				ok = false;
				break;
			}
			// cerr << i << " " << j << " " << par[j] << endl;
		}
		if (!ok)
			break;
	}
	cout << i + 1 << "\n";
	
	return 0;
}
// started coding at: 04-26 19:40:42

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 5380kb

input:

4
1 2
1 3
1 4

output:

4

result:

ok single line: '4'

Test #2:

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

input:

5
1 5
5 3
3 4
4 2

output:

3

result:

ok single line: '3'

Test #3:

score: 0
Accepted
time: 21ms
memory: 6600kb

input:

99999
81856 39633
81856 94012
99999 43062
99946 220
81856 46131
99933 36505
99939 35662
99952 70971
99999 3275
99938 58416
99976 66658
99991 87922
81856 80992
99933 6392
99951 41047
99970 54115
81856 38150
99934 73554
81856 64578
81856 18576
99951 67996
99938 84479
81856 39617
99999 18664
99946 2505...

output:

99925

result:

ok single line: '99925'

Test #4:

score: -100
Wrong Answer
time: 26ms
memory: 7484kb

input:

99997
90325 59106
22545 8765
88871 37709
14739 95233
8778 29659
48110 57549
91258 76066
15724 65144
48244 87291
12076 94378
41946 96707
93645 12812
53817 34343
72097 94062
81212 263
78713 78150
6754 94906
20957 97539
59293 5018
77961 78090
57262 95225
79349 47902
99024 7869
10613 13728
61757 41090
4...

output:

85396

result:

wrong answer 1st lines differ - expected: '85398', found: '85396'