# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
25811 | tlwpdus | 전압 (JOI14_voltage) | C++98 | 366 ms | 25160 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int n, m;
vector<int> lis[100100];
vector<int> id[100100];
int color[100100];
int s[100100], e[100100], son[200100];
int rev[200100];
bool visit[100100];
int tt, odd;
int od[200100], ev[200100];
void dfs(int here, int col, int ep) {
int i;
s[here] = tt;
tt++;
color[here] = col;
for (i=0;i<lis[here].size();i++) {
int there = lis[here][i];
if (id[here][i]==ep) continue;
if (color[there]) {
if (s[there]>s[here]) continue;
rev[id[here][i]] = ((color[here]==color[there])?1:2);
if (color[here]==color[there]) odd++;
int *p = ((color[here]==color[there])?od:ev);
p[here]++; p[there]--;
continue;
}
son[id[here][i]] = there;
dfs(there,3-col,id[here][i]);
}
e[here] = tt;
}
int res;
void fdfs(int here, int p) {
int i;
visit[here] = true;
for (i=0;i<lis[here].size();i++) {
int there = lis[here][i];
if (visit[there]) continue;
fdfs(there,here);
ev[here]+=ev[there];
od[here]+=od[there];
}
if (od[here]==odd&&ev[here]==0&&p!=-1) res++;
}
int main() {
int i;
scanf("%d%d",&n,&m);
for (i=0;i<m;i++) {
int a, b;
scanf("%d%d",&a,&b);
a--;b--;
lis[a].push_back(b);
id[a].push_back(i);
lis[b].push_back(a);
id[b].push_back(i);
}
for (i=0;i<n;i++) {
if (color[i]) continue;
dfs(i,1,-1);
}
for (i=0;i<n;i++) {
if (visit[i]) continue;
fdfs(i,-1);
}
for (i=0;i<m;i++) if (rev[i]==1&&odd==1) res++;
printf("%d\n",res);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |