QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#405333#5655. Train SplittinghongjinjianWA 27ms3652kbC++231.2kb2024-05-05 17:32:172024-05-05 17:32:18

Judging History

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

  • [2024-05-05 17:32:18]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:3652kb
  • [2024-05-05 17:32:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e3 + 10;
const int MOD = 998244353;

int n, m;
vector<int>v[N];
int ans[N];
int ind[N];

void solve() {
	cin >> n >> m;
	for (int i = 1; i <= m; i++) ans[i] = 0;
	for (int i = 1; i <= n; i++) v[i].clear(), ind[i] = 0;
	for (int i = 1; i <= m; i++)
	{
		int x, y;
		cin >> x >> y;
		v[x].push_back(i);
		v[y].push_back(i);
		ind[x]++, ind[y]++;
	}
	if (n == 3)
	{
		cout << m << "\n";
		for (int j = 1; j <= m; j++) cout << j << " ";
		cout << "\n";
		return;
	}
	if (m == n * (n - 1) / 2)
	{
		ans[v[1][0]] = 1;
		for (int i = 1; i < v[1].size(); i++)
			ans[i] = 2;
		cout << "3\n";
		for (int i = 1; i <= m; i++)
		{
			if (!ans[i]) ans[i] = 3;
			cout << ans[i] << " ";
		}
		cout << "\n";
		return;
	}
	cout << "2\n";
	int minn = 1;
	for (int i = 1; i <= n; i++)
		if (ind[i] < ind[minn]) minn = i;
	for (auto y : v[minn]) ans[y] = 1;
	for (int i = 1; i <= m; i++)
	{
		if (!ans[i]) ans[i] = 2;
		cout << ans[i] << " ";
	}
	cout << "\n";
}

int main() 
{
	int tt = 1;
	cin >> tt;
	while (tt--)
		solve();
	//system("pause");
	return 0;
}

详细

Test #1:

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

input:

2
5 9
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
3 3
1 2
3 1
2 3

output:

2
2 2 1 2 2 1 2 1 2 
3
1 2 3 

result:

ok OK (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 27ms
memory: 3632kb

input:

100
50 1225
15 33
19 23
14 8
23 26
5 46
22 8
22 13
16 10
20 12
32 16
2 5
36 43
20 33
35 8
4 11
15 43
4 26
33 1
25 36
49 6
11 2
35 11
39 20
24 7
41 2
10 9
40 49
27 17
26 11
49 39
46 27
24 44
26 34
6 27
25 22
9 46
29 43
50 43
2 37
37 10
28 5
14 5
23 28
37 40
10 45
9 26
23 29
35 47
32 21
16 11
9 50
50 ...

output:

3
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...

result:

wrong answer color 3 is connected (test case 1)