QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#558398 | #852. Jellyfish | rotcar07 | WA | 210ms | 3948kb | C++20 | 683b | 2024-09-11 15:54:00 | 2024-09-11 15:54:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int maxn=1e5+5;
int n;
vector<int> e[maxn];
int deg[maxn];
inline void solve(){
cin>>n;
for(int i=1;i<=n;i++) e[i].clear();
for(int i=1,u,v;i<=n;i++) cin>>u>>v,e[u].push_back(v),e[v].push_back(u),deg[u]++,deg[v]++;
int ans=0;
queue<int> q;
for(int i=1;i<=n;i++) if(deg[i]==1) q.push(i),ans++;
while(!q.empty()){
int p=q.front();q.pop();
for(auto x:e[p]) if(--deg[x]==1) q.push(x);
}
int cnt=0;
for(int i=1;i<=n;i++) if(deg[i]>1&&e[i].size()==2) cnt++;
cout<<max(3,ans+min(cnt,2))<<'\n';
}
int main(){
int t;cin>>t;
while(t--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3568kb
input:
2 6 1 2 2 3 3 4 4 1 2 5 2 6 4 1 2 2 3 3 4 4 1
output:
4 3
result:
ok 2 number(s): "4 3"
Test #2:
score: -100
Wrong Answer
time: 210ms
memory: 3948kb
input:
85665 6 3 2 4 1 4 6 2 1 2 6 5 1 7 6 2 6 3 5 1 1 2 2 4 4 7 3 7 7 6 1 6 7 1 4 1 3 7 5 5 3 4 2 7 6 2 7 4 7 5 3 1 3 4 2 5 1 4 7 7 2 2 6 5 4 5 6 5 1 3 1 4 6 7 3 5 3 1 3 7 3 2 5 1 5 4 4 6 7 4 5 4 1 3 6 3 7 6 7 6 1 2 1 7 5 3 7 3 1 4 6 2 6 3 2 3 4 3 7 2 3 2 6 2 4 7 5 3 5 5 1 1 4 7 3 4 3 7 5 6 2 7 4 6 6 7 6 ...
output:
4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 8 3 3 3 3 3 3 67 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 20 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...
result:
wrong answer 6th numbers differ - expected: '4', found: '3'