QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#702901 | #8333. Gift | garhlz | RE | 1ms | 7044kb | C++14 | 1.9kb | 2024-11-02 16:46:18 | 2024-11-02 16:46:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
vector<int> v[N];
#define pii array<int,2>
vector<pii> ed;
int vis[N];
int siz[N],mx[N];//分别是全部子树数量和最大儿子数量
stack<int> st;
int flag = 0;
int ans =0 ;
void dfs1(int x,int f){
for(int y : v[x]){
if(flag)return;
if(y==f)continue;
if(vis[y]){//已经是环了
int x = st.top();
st.pop();
int last = x;
while(!st.empty()&&st.top()!=x){
int now = st.top();
ed.push_back({last,now});
st.pop();
last = now;
}
ed.push_back({last,x});
flag = 1;
return;
}
vis[y] = 1;
st.push(y);
dfs1(y,x);
st.pop();
}
}
int du[N];
void solve(){
int n;
cin>>n;
for(int i = 1;i<=n;i++){
int a,b;
cin>>a>>b;
du[a]++;
du[b]++;
v[a].push_back(b);
v[b].push_back(a);
}
map<int,int> mp;
st.push(1);
vis[1] = 1;
dfs1(1,0);
int mx = 0;
for(int i = 1;i<=n;i++){
mx = max(mx,du[i]);
mp[du[i]]++;
}
if(mx>5){
cout<<0<<'\n';
return;
}
int ans = 0;
for(auto h : ed){
int x = h[0],y = h[1];
int dx = du[x],dy = du[y];
mp[dx]--,mp[dy]--;
mp[dx-1]++,mp[dy-1]++;
if(mp[5]==0){
ans+=mp[3];
ans+=mp[2];
ans+=mp[1];
}
mp[dx]++,mp[dy]++;
mp[dx-1]--,mp[dy-1]--;
}
cout<<ans<<'\n';
}
/*
6
1 2
1 3
1 4
1 5
1 6
2 3
*/
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
// cin>>t;
while(t--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5924kb
input:
6 1 2 1 3 1 4 1 5 1 6 2 3
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7044kb
input:
3 1 3 3 2 2 1
output:
9
result:
ok 1 number(s): "9"
Test #3:
score: -100
Runtime Error
input:
2332 1648 909 1676 2122 1644 1981 1106 1131 1785 239 223 618 335 1662 424 1775 889 1684 1589 52 1406 1747 1600 302 790 2056 1742 464 1706 541 1145 779 2316 833 1645 1439 859 438 1337 136 746 1565 436 1730 2079 2145 1583 1940 917 1549 1863 507 1266 367 1890 2230 13 2113 492 2109 120 1122 815 1111 134...