QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#84034#5655. Train SplittingBervigWA 1ms3372kbC++141.2kb2023-03-05 03:54:472023-03-05 03:54:48

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-05 03:54:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3372kb
  • [2023-03-05 03:54:47]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;


void solve() {
	
	int t;
	cin >> t;
	while(t--){
		int n,m;
		cin >> n >> m;
	
		vector<vector<int> > adj(n+1,vector<int>());
		vector<pair<int,int> > listRoutes(m);
		int a,b;
		for(int i=0;i<m;i++){
			cin >> a >> b;
			listRoutes[i] = {a,b};
			adj[a].push_back(b);
			adj[b].push_back(a);
		}


		int finalNode = -1;
		int minDegree = 1e9;
		int minNode = -1;
		for(int i=1;i<=n;i++){
			if(adj[i].size() == 1){
				finalNode = i;
			}
			if((int)adj[i].size() < minDegree){
				minDegree = adj[i].size();
				minNode = i;
			}
		}

		if(finalNode != -1){
			cout << 2 << endl;
			for(int i=0;i<m;i++){
				if(listRoutes[i].first == finalNode || listRoutes[i].second == finalNode){
					cout << 1 << " ";
				}else{
					cout << 2 << " ";
				}
			}

		}else{
			cout << 3 << endl;
			int cnt = 0;
			for(auto p : listRoutes){
				if(p.first == minNode || p.second == minNode){
					cnt++;
					if(cnt == minDegree){
						cout << 3 << " ";
					}else{
						cout << 1 << " ";
					}
				}else{
					cout << 2 << " ";
				}
			}

		}
		cout << endl;


	}

}

int main() {


	solve();

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3372kb

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:

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

result:

wrong answer colors 1 and 3 are not connected (test case 1)