QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#288444 | #5655. Train Splitting | Sorting# | WA | 1ms | 3572kb | C++14 | 1.3kb | 2023-12-22 17:32:21 | 2023-12-22 17:32:22 |
Judging History
answer
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <functional>
using namespace std;
typedef long long ll;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t--){
int n, m;
cin >> n >> m;
if(n == 3 && m == 2){
for(int i = 0; i < m; ++i){
int x, y;
cin >> x >> y;
}
cout << "2\n1 2\n";
continue;
}
vector<pair<int, int>> edges;
vector<int> cnt(n + 1);
for(int i = 0; i < m; ++i){
int u, v;
cin >> u >> v;
edges.push_back({u, v});
++cnt[u];
++cnt[v];
}
int root;
for(int i = 1; i <= n; ++i){
if(cnt[i] >= 2)
root = i;
}
cout << "3\n";
for(int i = 0; i < m; ++i){
auto [u, v] = edges[i];
if(u != root) swap(u, v);
if(u != root && v != root){
cout << "1 ";
}
else{
if(v & 1) cout << "2 ";
else cout << "3 ";
}
}
cout << "\n";
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3572kb
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 1 1 1 2 1 1 3 1 2 3 1 2 3
result:
wrong answer colors 2 and 3 are not connected (test case 1)