Submission #132605

#TimeUsernameProblemLanguageResultExecution timeMemory
132605abra_stone산만한 고양이 (KOI17_cat)C++14
10 / 100
334 ms35320 KiB
#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)

cat.cpp: In function 'll f(ll, ll)':
cat.cpp:16:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i = 0; i < gr[p].size(); i++) {
              ~~^~~~~~~~~~~~~~
cat.cpp: In function 'bool g(ll, ll)':
cat.cpp:30:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i = 0; i < gr[p].size(); i++) {
              ~~^~~~~~~~~~~~~~
cat.cpp:27:12: warning: unused variable 't' [-Wunused-variable]
  ll i, ne, t;
            ^
cat.cpp: In function 'int main()':
cat.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &t1, &t2);
   ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...