QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#288444#5655. Train SplittingSorting#WA 1ms3572kbC++141.3kb2023-12-22 17:32:212023-12-22 17:32:22

Judging History

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

  • [2023-12-22 17:32:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3572kb
  • [2023-12-22 17:32:21]
  • 提交

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)