# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
132605 | abra_stone | 산만한 고양이 (KOI17_cat) | C++14 | 334 ms | 35320 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <cstdio>
#include <vector>
#define N 300005
using namespace std;
typedef long long ll;
ll n, m, ans, b;
vector<ll> gr[N];
bool v[N], v1[N];
ll f(ll p, ll pa) {
ll i, ne, t;
if (v[p]) return p;
v[p] = 1;
for (i = 0; i < gr[p].size(); i++) {
ne = gr[p][i];
if (ne != pa) {
t = f(ne, p);
if (t) return t;
}
}
return 0;
}
bool g(ll p, ll pa) {
ll i, ne, t;
if (v1[p]) return 1;
v1[p] = 1;
for (i = 0; i < gr[p].size(); i++) {
ne = gr[p][i];
if (ne != pa && g(ne, p)) {
ans += p;
return 1;
}
}
return 0;
}
int main()
{
int i, t1, t2;
cin >> n >> m;
for (i = 0; i < n; i++) {
scanf("%d %d", &t1, &t2);
gr[t1].push_back(t2);
gr[t2].push_back(t1);
}
g(f(1, 0), 0);
cout << ans << endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |