QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#371713#6396. Puzzle: Kusabimoonshy#WA 26ms11540kbC++201.5kb2024-03-30 15:09:152024-03-30 15:09:15

Judging History

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

  • [2024-03-30 15:09:15]
  • 评测
  • 测评结果:WA
  • 用时:26ms
  • 内存:11540kb
  • [2024-03-30 15:09:15]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, string> PIS;
typedef pair<int, int> PII;

const int N = 1e5 + 5;

vector<PIS> p[N];
int st[N];

void solve() {
	int n;
	cin >> n;
	for (int i = 0; i < n - 1; i ++ ) {
		int x, y;
		string s;
		cin >> x >> y >> s;
		p[y].push_back({x, s});
	}
	queue<int> q;
	q.push(1);
	vector<PII> l, s, t;
	while (!q.empty()) {
		int ver = q.front();
		q.pop();
		for (auto x : p[ver]) {
			int u = x.first;
			st[u] = st[ver] + 1;
			//cout << x.second << '\n';
			if (x.second == "Chang") l.push_back({st[u], u});
			if (x.second ==  "Duan") s.push_back({st[u], u});
			if (x.second ==  "Tong") t.push_back({st[u], u}); 
			q.push(u);
		}
	}
	sort(l.begin(), l.end());
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	int len1 = s.size();
	if (l.size() != len1) {
		cout << "NO" << '\n';
		return;
	}
	for (int i = 0; i < len1; i ++ ) {
		if (s[i].first >= l[i].first) {
			cout << "NO" << '\n';
			return;
		}
	}
	int len2 = t.size();
	for (int i = 0; i < len2; i += 2 ) {
		if (i + 1 >= len2 || t[i].first != t[i + 1].first) {
			cout << "NO" << '\n';
			return;
		}
	}
	cout << "YES" << '\n';
	for (int i = 0; i < len1; i ++ ) cout << s[i].second << ' ' << l[i].second << '\n';
	for (int i = 0; i < len2; i += 2 ) cout << t[i].second << ' ' << t[i + 1].second << '\n';
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

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

詳細信息

Test #1:

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

input:

8
2 1 -
3 1 -
4 2 Tong
5 2 Tong
6 3 Duan
7 3 -
8 7 Chang

output:

YES
6 8
4 5

result:

ok Correct.

Test #2:

score: 0
Accepted
time: 1ms
memory: 3612kb

input:

10
2 1 Duan
3 2 Duan
4 2 -
5 4 Chang
6 2 Chang
7 1 Duan
8 6 Tong
9 6 Tong
10 3 Chang

output:

YES
2 6
7 5
3 10
8 9

result:

ok Correct.

Test #3:

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

input:

2
2 1 Tong

output:

NO

result:

ok Correct.

Test #4:

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

input:

100000
2 1 Duan
3 1 Duan
4 3 -
5 4 Duan
6 3 -
7 4 Duan
8 4 -
9 8 -
10 7 Duan
11 9 -
12 7 Duan
13 7 Duan
14 8 Duan
15 13 -
16 10 Duan
17 11 Duan
18 12 -
19 1 Duan
20 5 Duan
21 4 Duan
22 14 Duan
23 16 -
24 22 Duan
25 16 Duan
26 13 -
27 13 -
28 17 -
29 5 Duan
30 22 -
31 23 -
32 9 Duan
33 5 -
34 30 Duan...

output:

YES
2 12996
3 20666
19 38925
66 40169
113 52481
135 92154
216 265
248 2685
692 3809
1354 5943
25684 11039
40 12128
70 12888
110 14272
124 17146
139 19308
145 25068
206 30140
246 36436
313 36449
527 37334
551 38037
654 38832
800 39171
818 40767
1169 43284
1359 50915
1389 51406
1510 58572
1977 61840
2...

result:

wrong answer Edge 2-1 used twice.