QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#637764 | #8332. Two in One | Nanami | WA | 0ms | 6068kb | C++17 | 1.9kb | 2024-10-13 14:02:18 | 2024-10-13 14:02:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n;
int ans;
int d[N];
bool b[N];
int sum, p;
int a[N], cnt, cntfin;
vector <int> e[N];
map <pair <int, int>, bool> edge;
void dfs(int u, int x) {
b[u] = 1;
a[++ cnt] = u;
// cout << cnt << " " << u << endl;
for(auto v : e[u]) {
if(edge[{u, v}] || edge[{v, u}]) continue;
if(p) return;
if(b[v]) {
// sum = x;
// cout << sum << endl;
p = 1;
a[++ cnt] = v;
// cout << cnt << endl;
cntfin = cnt;
// for(int i = 1; i <= cntfin; i ++) cout << a[i] << " ";
return;
}
// cout << v << " " << x + 1 << endl;
edge[{u, v}] = 1;
edge[{v, u}] = 1;
dfs(v, x + 1);
edge[{u, v}] = 0;
edge[{v, u}] = 0;
if(p) return;
b[v] = 0;
cnt --;
}
return;
}
int main() {
cin >> n;
for(int i = 1; i <= n; i ++) {
int u, v;
cin >> u >> v;
// b[i] = 0;
// sum += 2;
d[u] ++;
d[v] ++;
e[u].push_back(v);
e[v].push_back(u);
}
// a[1] = 1;
dfs(1, 1);
// cout << sum << endl;
int sta = a[cntfin];
int cancut = 0;
int howmany = 0;
int du = 0;
for(int i = cntfin; i >= 1; i --) {
if(i != cntfin && sta == a[i]) break;
if(d[a[i]] >= 5) {
du ++;
if(du == 1)
cancut = 2;
else if(du > 1)
cancut = 1;
}
howmany ++;
}
// cout << howmany << endl;
if(cancut == 0) cancut = howmany;
int ans = 0;
for(int i = 1; i <= n; i ++) {
if(d[i] >= 4) continue;
else ans += cancut;
}
cout << ans << endl;
// cout << sum << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 6068kb
input:
1 7 1 2 3 4 3 2 1
output:
0
result:
wrong answer 1st numbers differ - expected: '3', found: '0'