# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
581932 |
2022-06-23T08:18:29 Z |
반딧불(#8365) |
전압 (JOI14_voltage) |
C++14 |
|
1000 ms |
16976 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
vector<pair<int, int> > link[200002];
int ex[200002], ey[200002];
bool usedInTree[200002];
vector<int> remEdge;
int ans;
bool visited[200002];
bool col[200002];
bool isWrong[200002];
int in[200002], out[200002], inCnt;
int depth[200002];
void tree_dfs(int x){
visited[x] = 1;
in[x] = ++inCnt;
for(auto y: link[x]){
if(visited[y.first]) continue;
usedInTree[y.second] = true;
col[y.first] = !col[x];
depth[y.first] = depth[x]+1;
tree_dfs(y.first);
}
out[x] = inCnt;
}
int main(){
scanf("%d %d", &n, &m);
for(int i=1; i<=m; i++){
int x, y;
scanf("%d %d", &x, &y);
link[x].push_back(make_pair(y, i));
link[y].push_back(make_pair(x, i));
ex[i] = x, ey[i] = y;
}
tree_dfs(1);
for(int i=1; i<=m; i++) if(!usedInTree[i]) remEdge.push_back(i);
for(int i=1; i<=n; i++) link[i].clear();
for(int i=1; i<=m; i++){
if(usedInTree[i]) link[ex[i]].push_back(make_pair(ey[i], i)), link[ey[i]].push_back(make_pair(ex[i], i));
else{
isWrong[i] = (col[ex[i]] == col[ey[i]]);
}
}
if(count(isWrong+1, isWrong+n+1, true) == 1) ans++;
for(int i=1; i<=m; i++){
if(!usedInTree[i]) continue;
int p = ex[i], x = ey[i];
if(depth[p] > depth[x]) swap(x, p);
bool bad = 0;
for(auto e: remEdge){
bool a = isWrong[e];
bool b = (in[x] <= in[ex[e]] && in[ex[e]] <= out[x]) ^
(in[x] <= in[ey[e]] && in[ey[e]] <= out[x]);
if(a!=b){
bad=1;
break;
}
}
if(!bad) ans++;
}
printf("%d", ans);
}
Compilation message
voltage.cpp: In function 'int main()':
voltage.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
voltage.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5028 KB |
Output is correct |
3 |
Incorrect |
3 ms |
5076 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
11204 KB |
Output is correct |
2 |
Correct |
68 ms |
14512 KB |
Output is correct |
3 |
Correct |
45 ms |
11640 KB |
Output is correct |
4 |
Correct |
73 ms |
15592 KB |
Output is correct |
5 |
Correct |
10 ms |
5812 KB |
Output is correct |
6 |
Correct |
78 ms |
13244 KB |
Output is correct |
7 |
Correct |
87 ms |
16972 KB |
Output is correct |
8 |
Correct |
77 ms |
16976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
11148 KB |
Output is correct |
2 |
Correct |
41 ms |
16568 KB |
Output is correct |
3 |
Correct |
66 ms |
16588 KB |
Output is correct |
4 |
Incorrect |
4 ms |
4948 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1092 ms |
13704 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |