QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#405325#5655. Train SplittinghongjinjianRE 0ms0kbC++201.2kb2024-05-05 17:25:522024-05-05 17:25:53

Judging History

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

  • [2024-05-05 17:25:53]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-05-05 17:25:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 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: 0
Dangerous Syscalls

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 

result: