답안 #132550

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
132550 2019-07-19T07:11:37 Z sean617 산만한 고양이 (KOI17_cat) C++
35 / 100
1097 ms 28516 KB
#include <iostream>
#include <cstdio>
#include <vector>
#define N 300005
using namespace std;

typedef long long ll;
ll n, m, k, s, v[N], cnt[N], v2[N];
bool z, u[N];
vector<ll> a[N], k1, k2;
void f(ll p, ll q) {
	ll i, num;
	if (v[p] == k) {z = 1; return;}
	v[p] = k;
	for (i =0; i < a[p].size(); i++) {
		num = a[p][i];
		if (num == q || num == k) continue;
		f(num, p);
	}
}

void g(ll p, ll q) {
	ll i;
	if (v2[p]) {
		s += p;
		for (p = q; p != k; p = v2[p]) s += p;
		return;
	}
	v2[p] = q;
	for (i = 0; i < a[p].size(); i++) {
		if (a[p][i] == q) continue;
		g(a[p][i], p);
	}
}
int main()
{
	ll i, j, t1, t2;
	cin >> n >> m;
	for (i = 1; i <= m; i++) {
		scanf ("%lld %lld", &t1, &t2);
		a[t1].push_back(t2);
		a[t2].push_back(t1);
		if (t1 > t2) swap(t1, t2);
		if (t1 == t2 -1) u[t1] = 1;
		else if (t1 == 1 && t2 == n) u[n] = 1;
		else {
			k1.push_back(t1);
			k2.push_back(t2);
		}
	}

	if (n <= 5000 && m <= 5000) {
		for (k = 1; k <= n; k++) {
			for (j = 1; j <= n; j++) {
				if (v[j] == k || j == k) continue;
				z = 0;
				f(j, 0);
				if (z) break;
			}
			if (j > n) s += k;
		}
		cout << s;
		return 0;
	}
	for (i = 1; i <= n; i++) {
		if (!u[i]) break;
	}
	if (i > n) {
		for (i = 0; i < k1.size(); i++) {
			cnt[k1[i]]++;
			cnt[k2[i]]++;
		}
		for (i = 1; i <= n; i++) {
			if (cnt[i] == k1.size()) s += i;
		}
		cout << s;
		return 0;
	}
	if (n == m) {
		for (i = 1; i <= n; i++) {
			if (a[i].size() == 3) break;
		}
		if (i > n) {
			cout << n * (n + 1) / 2;
		} else {
			k = i;
			g(i, 0);
			cout << s + k;
		}
		return 0;
	}

    cout << 0;
    return 0;
}

Compilation message

cat.cpp: In function 'void f(ll, ll)':
cat.cpp:15:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i =0; i < a[p].size(); i++) {
             ~~^~~~~~~~~~~~~
cat.cpp: In function 'void g(ll, ll)':
cat.cpp:30:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i = 0; i < a[p].size(); i++) {
              ~~^~~~~~~~~~~~~
cat.cpp: In function 'int main()':
cat.cpp:69:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (i = 0; i < k1.size(); i++) {
               ~~^~~~~~~~~~~
cat.cpp:74:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (cnt[i] == k1.size()) s += i;
        ~~~~~~~^~~~~~~~~~~~
cat.cpp:40:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%lld %lld", &t1, &t2);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 8 ms 7388 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7416 KB Output is correct
5 Correct 647 ms 8056 KB Output is correct
6 Correct 706 ms 7832 KB Output is correct
7 Correct 453 ms 8056 KB Output is correct
8 Correct 692 ms 7848 KB Output is correct
9 Correct 505 ms 8184 KB Output is correct
10 Correct 643 ms 7928 KB Output is correct
11 Correct 523 ms 8056 KB Output is correct
12 Correct 573 ms 7984 KB Output is correct
13 Correct 611 ms 7928 KB Output is correct
14 Correct 701 ms 8052 KB Output is correct
15 Correct 8 ms 7416 KB Output is correct
16 Correct 8 ms 7416 KB Output is correct
17 Correct 8 ms 7416 KB Output is correct
18 Correct 8 ms 7416 KB Output is correct
19 Correct 8 ms 7416 KB Output is correct
20 Correct 421 ms 8056 KB Output is correct
21 Correct 1097 ms 8184 KB Output is correct
22 Correct 1026 ms 7928 KB Output is correct
23 Correct 221 ms 7800 KB Output is correct
24 Correct 211 ms 7800 KB Output is correct
25 Correct 8 ms 7416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 309 ms 28516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 19872 KB Output is correct
2 Correct 118 ms 18652 KB Output is correct
3 Correct 118 ms 18680 KB Output is correct
4 Correct 118 ms 18652 KB Output is correct
5 Correct 117 ms 18680 KB Output is correct
6 Correct 118 ms 18780 KB Output is correct
7 Correct 118 ms 18808 KB Output is correct
8 Correct 118 ms 18652 KB Output is correct
9 Correct 118 ms 18680 KB Output is correct
10 Correct 138 ms 22232 KB Output is correct
11 Correct 139 ms 22116 KB Output is correct
12 Correct 153 ms 22236 KB Output is correct
13 Correct 142 ms 22292 KB Output is correct
14 Correct 140 ms 22092 KB Output is correct
15 Correct 159 ms 22360 KB Output is correct
16 Correct 156 ms 22452 KB Output is correct
17 Correct 158 ms 22364 KB Output is correct
18 Correct 164 ms 22360 KB Output is correct
19 Correct 177 ms 22488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 8 ms 7388 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7416 KB Output is correct
5 Correct 647 ms 8056 KB Output is correct
6 Correct 706 ms 7832 KB Output is correct
7 Correct 453 ms 8056 KB Output is correct
8 Correct 692 ms 7848 KB Output is correct
9 Correct 505 ms 8184 KB Output is correct
10 Correct 643 ms 7928 KB Output is correct
11 Correct 523 ms 8056 KB Output is correct
12 Correct 573 ms 7984 KB Output is correct
13 Correct 611 ms 7928 KB Output is correct
14 Correct 701 ms 8052 KB Output is correct
15 Correct 8 ms 7416 KB Output is correct
16 Correct 8 ms 7416 KB Output is correct
17 Correct 8 ms 7416 KB Output is correct
18 Correct 8 ms 7416 KB Output is correct
19 Correct 8 ms 7416 KB Output is correct
20 Correct 421 ms 8056 KB Output is correct
21 Correct 1097 ms 8184 KB Output is correct
22 Correct 1026 ms 7928 KB Output is correct
23 Correct 221 ms 7800 KB Output is correct
24 Correct 211 ms 7800 KB Output is correct
25 Correct 8 ms 7416 KB Output is correct
26 Incorrect 309 ms 28516 KB Output isn't correct
27 Halted 0 ms 0 KB -