QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#292877 | #6307. Chase Game 2 | Ycfhnnd | WA | 5ms | 3456kb | C++20 | 991b | 2023-12-28 15:53:43 | 2023-12-28 15:53:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve(){
int n;
cin >> n;
vector<vector<int>>adj(n + 1);
for (int i = 0;i < n - 1;i ++){
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 1;i <= n;i ++){
if (adj[i].size() == n - 1){
cout << -1 << '\n';
return;
}
}
vector<int>dep(n + 1);
int cnt = 0;
auto dfs = [&](auto self, int u, int p) -> void{
dep[u] = dep[p] + 1;
for (auto v : adj[u]){
if (v == p) continue;
self(self, v, u);
}
if (adj[u].size() == 1 && u != 1){
cnt ++;
}
};dfs(dfs, 1, 0);
cout << cnt << '\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
cin >> T;
while (T --){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3436kb
input:
4 2 1 2 4 1 2 2 3 3 4 4 1 2 2 3 2 4 5 1 2 2 3 3 4 3 5
output:
-1 1 -1 2
result:
ok 4 number(s): "-1 1 -1 2"
Test #2:
score: -100
Wrong Answer
time: 5ms
memory: 3456kb
input:
10000 4 1 2 1 3 3 4 4 1 2 1 3 1 4 4 1 2 2 3 1 4 5 1 2 2 3 1 4 4 5 5 1 2 2 3 3 4 4 5 4 1 2 2 3 2 4 5 1 2 1 3 2 4 2 5 4 1 2 2 3 1 4 5 1 2 1 3 2 4 1 5 5 1 2 2 3 3 4 2 5 5 1 2 1 3 2 4 2 5 4 1 2 1 3 3 4 5 1 2 1 3 3 4 1 5 4 1 2 1 3 1 4 5 1 2 1 3 3 4 3 5 5 1 2 2 3 3 4 3 5 4 1 2 1 3 2 4 5 1 2 2 3 2 4 3 5 5 ...
output:
2 -1 2 2 1 -1 3 2 3 2 3 2 3 -1 3 2 2 2 3 1 2 2 -1 3 2 2 1 -1 2 2 3 1 2 -1 2 3 2 1 2 -1 2 2 2 3 3 2 1 1 -1 2 2 1 2 2 2 3 2 2 3 -1 -1 -1 2 3 3 2 2 2 3 3 3 -1 2 3 -1 2 2 -1 3 -1 -1 2 3 3 2 2 2 2 1 1 1 2 2 2 3 -1 2 2 3 -1 3 2 2 2 -1 3 -1 2 -1 -1 3 -1 3 1 2 3 2 2 2 2 2 2 2 1 2 -1 2 1 3 1 1 2 2 2 2 2 3 -1...
result:
wrong answer 1st numbers differ - expected: '1', found: '2'