QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#664254 | #8333. Gift | AI80 | WA | 2ms | 3720kb | C++20 | 3.3kb | 2024-10-21 19:52:43 | 2024-10-21 19:52:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define lowbit(x) (x & (-x))
typedef long long ll;
typedef pair<int,int> pii;
mt19937 rnd(time(0));
const int N = 1e6 + 7;
const int mod = 998244353;
const int P = rnd() % mod;
vector<int> v[N];
vector<int> pre[N];
int vis[N];
void solve() {
int n; cin >> n;
for(int i = 1;i <= n;i++) {
int l , r; cin >> l >> r;
v[l].push_back(r);
v[r].push_back(l);
}
for(int i = 1;i <= n;i++) {
if(v[i].size() == 1) {
queue<int> q;
q.push(i);
pre[i].push_back(-1);
int fst = 0;
while(!q.empty()) {
int t = q.front();
q.pop();
for(auto x : v[t]) {
if(!pre[x].size()) {
pre[x].push_back(t);
q.push(x);
}
else if(x != pre[t].back()) {
pre[x].push_back(t);
fst = x;
break;
}
}
if(fst) break;
}
while(!q.empty()) q.pop();
q.push(fst);
while(!q.empty()) {
int t = q.front();
q.pop();
if(vis[t]) continue;
vis[t] = 1;
for(auto x : pre[t]) {
if(!vis[x]) {
q.push(x);
vis[x] = 1;
}
else {
int cnt = 0;
for(int i = 1;i <= n;i++) cnt += (vis[i]);
if(cnt % 2 == 0) break;
else {
vis[pre[x].back()] = 0;
break ;
}
}
}
}
break;
}
}
vector<int> vv;
for(int i = 1;i <= n;i++) {
if(vis[i]) vv.push_back(i);
}
int res = 0,ans = 0;
for(int i = 1;i <= n;i++) {
if(v[i].size() <= 3) res++;
}
for(int i = 0;i < vv.size();i++) {
if(v[i].size() == 5) {
for(auto x : v[i]) {
if(vis[x]) {
if(v[x].size() == 5) {
cout << res << "\n";
return ;
}
else ans += res + (v[x].size() == 4);
}
}
cout << ans << "\n";
return ;
}
}
for(int i = 0;i < vv.size();i++) {
if(v[i].size() == 4) {
for(auto x : v[i]) {
if(vis[x]) {
if(v[i].size() == 4) ans += res + 2;
else ans += res + 1;
}
}
}
else {
for(auto x : v[i]) {
if(vis[x]) {
if(v[i].size() == 4) ans += res + 1;
else ans += res;
}
}
}
}
cout << ans / 2 << "\n";
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
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: 2ms
memory: 3720kb
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: -100
Wrong Answer
time: 0ms
memory: 3716kb
input:
3 1 3 3 2 2 1
output:
0
result:
wrong answer 1st numbers differ - expected: '9', found: '0'