QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#875764#9911. 路南柯juruoA0 9ms3840kbC++112.4kb2025-01-30 12:31:562025-01-30 12:31:56

Judging History

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

  • [2025-01-30 12:31:56]
  • 评测
  • 测评结果:0
  • 用时:9ms
  • 内存:3840kb
  • [2025-01-30 12:31:56]
  • 提交

answer

#include <bits/stdc++.h>
using std::bitset;
using std::cout;
using std::deque;
using std::endl;
using std::greater;
using std::lower_bound;
using std::make_pair;
using std::map;
using std::max;
using std::min;
using std::multimap;
using std::multiset;
using std::nth_element;
using std::pair;
using std::priority_queue;
using std::queue;
using std::reverse; 
using std::set;
using std::sort;
using std::sqrt;
using std::stable_sort;
using std::string;
using std::swap;
using std::unique;
using std::upper_bound;
using std::vector;
typedef long long li;
typedef long double lf; 

inline long long read(){
	long long ans = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9'){
		f = (ch == '-') ? -1 : 1;
		ch = getchar();
	}
	while(ch <= '9' && ch >= '0'){
		ans = ans * 10 + (ch ^ 48);
		ch = getchar();
	}
	return ans * f;
} 

li n, m;
li degree[110], val[110];
vector<li> a[110], ans[110];

void dfs(li u, li fa){
    // cout << "u = " << u << endl;
    ans[m].push_back(u);
    vector<li> temp;
    for(li v : a[u]){
        if(v != fa && a[v].size() == 1) temp.push_back(v);
    }
    if(val[u] && temp.size()){
        reverse(temp.begin(), temp.end());
        val[u] ^= 1;
    }
    for(li v : temp) ans[m].push_back(v);
    for(li v : a[u]){
        if(v != fa && a[v].size() > 1) dfs(v, u);
    }
}

int main(){
    // freopen("wonderful.ans", "r", stdin);
    // freopen("www.ww", "w", stdout);
	li T = read();
    while(T--){
        m = 0, n = read();
        memset(degree, 0, sizeof degree);
        for(li i = 1; i <= n; i++) a[i].clear(), ans[i].clear();
        for(li i = 1; i < n; i++){
            li u = read(), v = read();
            degree[u]++, degree[v]++;
            a[u].push_back(v), a[v].push_back(u);
        }
        memset(degree, 0, sizeof degree);
        for(li i = 1; i <= n; i++){
            if(a[i].size() != 1){
                for(li j : a[i]){
                    degree[i] += (a[j].size() >= 2);
                }
                // cout << i << " " << degree[i] << endl;
                if(degree[i] == 1){
                    m++;
                    dfs(i, 0);
                    reverse(ans[i].begin(), ans[i].end());
                }
            }
        }
        printf("%lld\n", m);
        for(li i = 1; i <= m; i++){
            for(li v : ans[i]) printf("%lld ", v);
            printf("\n");
        }
    }
    return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

10
10
4 2
5 1
8 6
1 9
3 7
1 8
10 2
6 4
3 4
10
4 3
3 1
5 3
6 3
2 3
8 7
8 2
7 10
8 9
10
5 4
10 8
10 3
6 3
9 8
1 10
4 2
2 7
8 4
10
10 6
6 8
1 7
2 6
3 5
3 9
4 2
6 9
3 1
10
2 8
10 4
9 1
9 3
5 7
6 3
1 8
8 7
4 2
10
9 2
9 1
7 1
5 6
8 2
3 9
5 10
5 4
1 10
10
2 9
8 1
8 5
6 3
7 1
6 2
9 8
2 10
4 2
10
5 7
6 2
8 7...

output:

3
7 3 10 2 4 6 8 9 5 1 
7 3 9 5 1 8 6 4 10 2 
9 5 1 8 6 10 2 4 7 3 
2
3 4 1 5 6 2 8 9 7 10 
7 10 8 9 2 3 4 1 5 6 
2
2 7 4 5 8 9 10 1 3 6 
3 6 10 1 8 9 4 5 2 7 
2
4 2 8 10 6 9 5 3 7 1 
7 1 5 3 9 8 10 6 4 2 
3
3 6 9 1 8 2 4 10 7 5 
4 10 2 8 1 9 3 6 7 5 
7 5 8 2 4 10 1 9 3 6 
2
2 8 9 3 1 7 10 5 6 4 
5 ...

result:

wrong output format Extra information in the output file

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 9ms
memory: 3712kb

input:

100
100
90 19
79 98
23 34
50 41
31 52
61 19
50 30
49 5
95 65
22 44
72 89
49 77
27 7
48 2
28 25
56 12
97 63
98 43
10 4
50 33
12 13
54 16
100 43
23 69
53 5
56 85
39 6
64 92
100 59
2 71
44 29
59 97
64 39
75 53
59 89
16 35
67 16
6 43
38 51
36 22
58 70
3 29
9 61
99 11
49 95
27 72
73 89
23 3
14 3
61 57
26...

output:

15
4 10 75 53 5 49 77 25 28 94 95 65 38 51 22 44 68 29 3 14 23 34 60 69 73 42 89 72 27 7 59 100 43 98 79 45 47 6 24 39 66 64 92 84 37 40 88 76 91 26 20 93 35 16 67 78 54 48 2 71 52 31 97 63 62 90 19 61 9 57 82 15 87 80 21 81 33 50 41 30 83 46 86 70 58 8 55 99 11 18 32 74 96 56 85 12 13 1 36 17 
13 1...

result:

wrong output format Extra information in the output file