답안 #132627

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
132627 2019-07-19T08:57:44 Z sean617 산만한 고양이 (KOI17_cat) C++
45 / 100
1047 ms 34936 KB
#include <iostream>
#include <cstdio>
#include <vector>
#define N 300005
using namespace std;

typedef long long ll;
ll n, m, k, s, cy, v[N], cnt[N], v2[N];
bool z, u[N], y[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 (cy) return;
	if (y[p]) {
		cy = p;
		s += p;
		for (i = v2[p]; i != p; i = v2[i]) {
			s += i;
		}
		return;
	}
	y[p] = 1;
	for (i = 0; i < a[p].size(); i++) {
		if (a[p][i] == q) continue;
		v2[p] = a[p][i];
		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 == m) {
		g(1, 0);
		cout << s;
		return 0;
	}

	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;
	}

    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:34: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:79:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (i = 0; i < k1.size(); i++) {
               ~~^~~~~~~~~~~
cat.cpp:84:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (cnt[i] == k1.size()) s += i;
        ~~~~~~~^~~~~~~~~~~~
cat.cpp:45: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 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7416 KB Output is correct
5 Correct 11 ms 7800 KB Output is correct
6 Correct 11 ms 7800 KB Output is correct
7 Correct 11 ms 7928 KB Output is correct
8 Correct 11 ms 7800 KB Output is correct
9 Correct 11 ms 7928 KB Output is correct
10 Correct 630 ms 7928 KB Output is correct
11 Correct 508 ms 8056 KB Output is correct
12 Correct 502 ms 7928 KB Output is correct
13 Correct 595 ms 7928 KB Output is correct
14 Correct 750 ms 7896 KB Output is correct
15 Correct 10 ms 7420 KB Output is correct
16 Correct 10 ms 7288 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 457 ms 8060 KB Output is correct
21 Correct 1047 ms 8048 KB Output is correct
22 Correct 1020 ms 8056 KB Output is correct
23 Correct 217 ms 7800 KB Output is correct
24 Correct 215 ms 7864 KB Output is correct
25 Correct 9 ms 7416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 282 ms 25992 KB Output is correct
2 Correct 270 ms 27216 KB Output is correct
3 Correct 266 ms 27136 KB Output is correct
4 Correct 251 ms 26816 KB Output is correct
5 Correct 286 ms 27200 KB Output is correct
6 Correct 248 ms 27112 KB Output is correct
7 Correct 255 ms 27072 KB Output is correct
8 Correct 256 ms 27224 KB Output is correct
9 Correct 249 ms 27244 KB Output is correct
10 Correct 264 ms 27200 KB Output is correct
11 Correct 290 ms 27424 KB Output is correct
12 Correct 267 ms 27456 KB Output is correct
13 Correct 274 ms 27324 KB Output is correct
14 Correct 314 ms 27592 KB Output is correct
15 Correct 267 ms 27468 KB Output is correct
16 Correct 270 ms 30016 KB Output is correct
17 Correct 282 ms 30784 KB Output is correct
18 Correct 280 ms 29508 KB Output is correct
19 Correct 267 ms 30288 KB Output is correct
20 Correct 267 ms 29156 KB Output is correct
21 Correct 272 ms 28516 KB Output is correct
22 Correct 295 ms 33776 KB Output is correct
23 Correct 269 ms 34744 KB Output is correct
24 Correct 254 ms 28100 KB Output is correct
25 Correct 284 ms 34628 KB Output is correct
26 Correct 168 ms 34936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 17052 KB Output is correct
2 Correct 119 ms 17144 KB Output is correct
3 Correct 123 ms 17108 KB Output is correct
4 Correct 121 ms 17008 KB Output is correct
5 Correct 118 ms 17144 KB Output is correct
6 Correct 117 ms 17120 KB Output is correct
7 Correct 117 ms 17084 KB Output is correct
8 Correct 121 ms 17104 KB Output is correct
9 Correct 118 ms 17144 KB Output is correct
10 Correct 170 ms 20564 KB Output is correct
11 Correct 138 ms 20580 KB Output is correct
12 Correct 138 ms 20648 KB Output is correct
13 Correct 139 ms 20444 KB Output is correct
14 Correct 138 ms 20580 KB Output is correct
15 Correct 156 ms 20876 KB Output is correct
16 Correct 156 ms 20824 KB Output is correct
17 Correct 184 ms 20908 KB Output is correct
18 Correct 154 ms 20792 KB Output is correct
19 Correct 162 ms 20824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7416 KB Output is correct
5 Correct 11 ms 7800 KB Output is correct
6 Correct 11 ms 7800 KB Output is correct
7 Correct 11 ms 7928 KB Output is correct
8 Correct 11 ms 7800 KB Output is correct
9 Correct 11 ms 7928 KB Output is correct
10 Correct 630 ms 7928 KB Output is correct
11 Correct 508 ms 8056 KB Output is correct
12 Correct 502 ms 7928 KB Output is correct
13 Correct 595 ms 7928 KB Output is correct
14 Correct 750 ms 7896 KB Output is correct
15 Correct 10 ms 7420 KB Output is correct
16 Correct 10 ms 7288 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 457 ms 8060 KB Output is correct
21 Correct 1047 ms 8048 KB Output is correct
22 Correct 1020 ms 8056 KB Output is correct
23 Correct 217 ms 7800 KB Output is correct
24 Correct 215 ms 7864 KB Output is correct
25 Correct 9 ms 7416 KB Output is correct
26 Correct 282 ms 25992 KB Output is correct
27 Correct 270 ms 27216 KB Output is correct
28 Correct 266 ms 27136 KB Output is correct
29 Correct 251 ms 26816 KB Output is correct
30 Correct 286 ms 27200 KB Output is correct
31 Correct 248 ms 27112 KB Output is correct
32 Correct 255 ms 27072 KB Output is correct
33 Correct 256 ms 27224 KB Output is correct
34 Correct 249 ms 27244 KB Output is correct
35 Correct 264 ms 27200 KB Output is correct
36 Correct 290 ms 27424 KB Output is correct
37 Correct 267 ms 27456 KB Output is correct
38 Correct 274 ms 27324 KB Output is correct
39 Correct 314 ms 27592 KB Output is correct
40 Correct 267 ms 27468 KB Output is correct
41 Correct 270 ms 30016 KB Output is correct
42 Correct 282 ms 30784 KB Output is correct
43 Correct 280 ms 29508 KB Output is correct
44 Correct 267 ms 30288 KB Output is correct
45 Correct 267 ms 29156 KB Output is correct
46 Correct 272 ms 28516 KB Output is correct
47 Correct 295 ms 33776 KB Output is correct
48 Correct 269 ms 34744 KB Output is correct
49 Correct 254 ms 28100 KB Output is correct
50 Correct 284 ms 34628 KB Output is correct
51 Correct 168 ms 34936 KB Output is correct
52 Correct 118 ms 17052 KB Output is correct
53 Correct 119 ms 17144 KB Output is correct
54 Correct 123 ms 17108 KB Output is correct
55 Correct 121 ms 17008 KB Output is correct
56 Correct 118 ms 17144 KB Output is correct
57 Correct 117 ms 17120 KB Output is correct
58 Correct 117 ms 17084 KB Output is correct
59 Correct 121 ms 17104 KB Output is correct
60 Correct 118 ms 17144 KB Output is correct
61 Correct 170 ms 20564 KB Output is correct
62 Correct 138 ms 20580 KB Output is correct
63 Correct 138 ms 20648 KB Output is correct
64 Correct 139 ms 20444 KB Output is correct
65 Correct 138 ms 20580 KB Output is correct
66 Correct 156 ms 20876 KB Output is correct
67 Correct 156 ms 20824 KB Output is correct
68 Correct 184 ms 20908 KB Output is correct
69 Correct 154 ms 20792 KB Output is correct
70 Correct 162 ms 20824 KB Output is correct
71 Incorrect 259 ms 26452 KB Output isn't correct
72 Halted 0 ms 0 KB -