# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
129774 |
2019-07-13T08:06:05 Z |
송준혁(#3142) |
전압 (JOI14_voltage) |
C++14 |
|
98 ms |
18424 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int N, M, O, ans;
vector<pii> adj[101010];
int col[101010], id[101010], num;
int OS[202020], ES[202020], dep[202020];
int OV[101010], EV[1010];
bool color(int u, int b, int c){
if (col[u]){
if (col[u] != c) return false;
return true;
}
col[u] = c;
for (pii v : adj[u]){
if (v.second == b){
if (!color(v.first, b, c)) return false;
}
else if (!color(v.first, b, c*-1)) return false;
}
return true;
}
void dfs(int u, int p, int d){
id[u] = num++;
dep[u] = d;
for (pii v : adj[u]){
if (v.second == p || id[v.first] > id[u]) continue;
if (id[v.first]){
if ((d - dep[v.first]) & 1){
ES[v.second]++;
EV[u]++, EV[v.first]--;
}
else{
OS[v.second]++, O++;
OV[u]++, OV[v.first]--;
}
}
else {
dfs(v.first, v.second, d+1);
OV[u] += OV[v.first];
EV[u] += EV[v.first];
}
}
OS[p] += OV[u], ES[p] += EV[u];
}
int main(){
int u, v;
scanf("%d %d", &N, &M);
for (int i=1; i<=M; i++){
scanf("%d %d", &u, &v);
adj[u].push_back(pii(v, i));
adj[v].push_back(pii(u, i));
}
for (int i=1; i<=N; i++) if (!id[i]) dfs(i, 0, 1);
bool tf = false;
for (int i=1; i<=M; i++){
if (OS[i] == O && !ES[i]){
tf = true;
for (int j=1; j<=N; j++) if (!col[j]) tf = tf && color(j, i, 1);
break;
}
}
if (!tf) puts("0");
else{
for (int i=1; i<=M; i++) if (OS[i] == O && !ES[i]) ans++;
printf("%d\n", ans);
}
return 0;
}
Compilation message
voltage.cpp: In function 'int main()':
voltage.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &N, &M);
~~~~~^~~~~~~~~~~~~~~~~
voltage.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &u, &v);
~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2936 KB |
Output is correct |
2 |
Correct |
4 ms |
2808 KB |
Output is correct |
3 |
Correct |
5 ms |
2808 KB |
Output is correct |
4 |
Correct |
5 ms |
2808 KB |
Output is correct |
5 |
Correct |
5 ms |
2808 KB |
Output is correct |
6 |
Incorrect |
5 ms |
2936 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
9216 KB |
Output is correct |
2 |
Incorrect |
88 ms |
13520 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
8920 KB |
Output is correct |
2 |
Correct |
53 ms |
16868 KB |
Output is correct |
3 |
Correct |
52 ms |
16812 KB |
Output is correct |
4 |
Incorrect |
4 ms |
2808 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
10340 KB |
Output is correct |
2 |
Correct |
83 ms |
18424 KB |
Output is correct |
3 |
Correct |
6 ms |
3832 KB |
Output is correct |
4 |
Incorrect |
98 ms |
14456 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |