# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
25765 |
2017-06-24T05:35:03 Z |
김동현(#1079) |
전압 (JOI14_voltage) |
C++14 |
|
316 ms |
22672 KB |
#include <bits/stdc++.h>
using namespace std;
struct E{ int x, i; };
int n, m, vis[100010], cr, d[100010], ps[100010], pe[100010], cnt, dc, fl, ans;
vector<E> e[100010];
vector<int> t[100010];
void T_T(){ puts("0"); exit(0); }
void col(int x, int c){
vis[x] = c;
for(auto &i : e[x]){
if(vis[i.x] && vis[i.x] != 3 - c) fl = 0;
else if(!vis[i.x]) col(i.x, 3 - c);
}
}
const int sz = 131072;
struct Seg{
int dat[2 * sz];
void upd(int x, int v){ for(x += sz; x; x /= 2) dat[x] += v; }
int get(int s, int e){
int ret = 0;
for(s += sz, e += sz; s <= e; s /= 2, e /= 2){
if(s % 2 == 1) ret += dat[s++];
if(e % 2 == 0) ret += dat[e--];
}
return ret;
}
} S[2];
void g(int x, int p){
vis[x] = 1;
ps[x] = ++cnt;
for(auto &i : e[x]){
if(i.i == p) continue;
if(vis[i.x] && d[i.x] < d[x]){
int t = (d[i.x] + d[x]) & 1;
//printf("back %d - %d : %d\n", x, i.x, t);
if(!t) dc++;
S[t].upd(ps[i.x], -1);
S[t].upd(ps[x], 1);
}
else if(!vis[i.x]){
//printf("go %d -> %d\n", x, i.x);
t[x].push_back(i.x);
d[i.x] = d[x] + 1;
g(i.x, i.i);
}
}
pe[x] = cnt;
}
void f(int x){
for(auto &i : t[x]){
f(i);
int t0 = S[0].get(ps[i], pe[i]);
int t1 = S[1].get(ps[i], pe[i]);
//printf("%d -> %d : %d / %d\n", x, i, t0, t1);
if(t0 == dc && !t1) ans++;
}
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 0, x, y; i < m; i++){
scanf("%d%d", &x, &y);
e[x].push_back({y, i});
e[y].push_back({x, i});
}
for(int i = 1; i <= n; i++){
if(!vis[i]){
fl = 1;
col(i, 1);
if(!fl){
if(cr) T_T();
cr = i;
}
}
}
fill(vis + 1, vis + n + 1, 0);
if(!cr){
int rans = 0;
for(int i = 1; i <= n; i++){
if(vis[i]) continue;
ans = dc = 0;
g(i, -1);
if(dc > 1) ans = 0;
else if(dc == 1) ans = 1;
f(i);
rans += ans;
}
printf("%d\n", rans);
}
else{
g(cr, -1);
if(dc > 1) ans = 0;
else if(dc == 1) ans = 1;
f(cr);
printf("%d\n", ans);
}
}
Compilation message
voltage.cpp: In function 'int main()':
voltage.cpp:67:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
^
voltage.cpp:69:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &x, &y);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10452 KB |
Output is correct |
2 |
Correct |
0 ms |
10320 KB |
Output is correct |
3 |
Correct |
0 ms |
10460 KB |
Output is correct |
4 |
Correct |
0 ms |
10452 KB |
Output is correct |
5 |
Correct |
3 ms |
10452 KB |
Output is correct |
6 |
Correct |
0 ms |
10452 KB |
Output is correct |
7 |
Correct |
0 ms |
10452 KB |
Output is correct |
8 |
Correct |
3 ms |
10452 KB |
Output is correct |
9 |
Correct |
3 ms |
10452 KB |
Output is correct |
10 |
Correct |
0 ms |
10452 KB |
Output is correct |
11 |
Correct |
0 ms |
10452 KB |
Output is correct |
12 |
Correct |
0 ms |
10452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
15572 KB |
Output is correct |
2 |
Correct |
196 ms |
19104 KB |
Output is correct |
3 |
Correct |
66 ms |
15572 KB |
Output is correct |
4 |
Correct |
166 ms |
20080 KB |
Output is correct |
5 |
Correct |
9 ms |
11008 KB |
Output is correct |
6 |
Correct |
166 ms |
17124 KB |
Output is correct |
7 |
Correct |
166 ms |
21084 KB |
Output is correct |
8 |
Correct |
173 ms |
21088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
15572 KB |
Output is correct |
2 |
Correct |
73 ms |
21088 KB |
Output is correct |
3 |
Correct |
69 ms |
21088 KB |
Output is correct |
4 |
Correct |
0 ms |
10320 KB |
Output is correct |
5 |
Correct |
139 ms |
17280 KB |
Output is correct |
6 |
Correct |
149 ms |
15732 KB |
Output is correct |
7 |
Correct |
179 ms |
18248 KB |
Output is correct |
8 |
Correct |
216 ms |
19540 KB |
Output is correct |
9 |
Correct |
193 ms |
19056 KB |
Output is correct |
10 |
Correct |
176 ms |
18048 KB |
Output is correct |
11 |
Correct |
133 ms |
15732 KB |
Output is correct |
12 |
Correct |
173 ms |
17336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
16596 KB |
Output is correct |
2 |
Correct |
133 ms |
22672 KB |
Output is correct |
3 |
Correct |
0 ms |
10320 KB |
Output is correct |
4 |
Correct |
179 ms |
18860 KB |
Output is correct |
5 |
Correct |
186 ms |
19632 KB |
Output is correct |
6 |
Correct |
196 ms |
18740 KB |
Output is correct |
7 |
Correct |
306 ms |
20564 KB |
Output is correct |
8 |
Correct |
176 ms |
21212 KB |
Output is correct |
9 |
Correct |
316 ms |
19600 KB |
Output is correct |
10 |
Correct |
259 ms |
21396 KB |
Output is correct |
11 |
Correct |
243 ms |
19212 KB |
Output is correct |
12 |
Correct |
246 ms |
21540 KB |
Output is correct |
13 |
Correct |
219 ms |
17704 KB |
Output is correct |
14 |
Correct |
269 ms |
21900 KB |
Output is correct |
15 |
Correct |
223 ms |
21436 KB |
Output is correct |
16 |
Correct |
279 ms |
21004 KB |
Output is correct |
17 |
Correct |
303 ms |
18948 KB |
Output is correct |
18 |
Correct |
193 ms |
19440 KB |
Output is correct |