ACM 训练日志记录 · 思考 · 成长 提交 / 修改记录
王梓豪 / 题目列表训练档案
导出

2257C C. Spying on the Beaver

来源:Codeforces ★ 1200

本题活力0.35按难度、完成结果与训练证据估算

算法如山行则将至

题目描述

确定从根出发到特定节点的路径,用最少相机区分多个目标节点。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while (t--) {
        int n;
        cin>>n;
        int temp;
        for(int i=0;i<n-1;i++)
        {
        	cin>>temp;
		}
		cin>>n;
		vector<int> a(n);
		for(int i=0;i<n;i++) 
		{
			cin>>a[i];
		}
		int ans=n-1;
		sort(a.begin(),a.end());
		if(ans==0)
		{
			cout<<0<<endl;
		}
		else
		{
			cout<<ans<<' ';
			for(int i=1;i<n;i++)
			cout<<a[i]<<' ';
			cout<<endl;
		}
    }
    return 0;
}