제출 #25811

#제출 시각아이디문제언어결과실행 시간메모리
25811tlwpdus전압 (JOI14_voltage)C++98
100 / 100
366 ms25160 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

voltage.cpp: In function 'void dfs(int, int, int)':
voltage.cpp:22:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<lis[here].size();i++) {
               ^
voltage.cpp: In function 'void fdfs(int, int)':
voltage.cpp:43:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<lis[here].size();i++) {
               ^
voltage.cpp: In function 'int main()':
voltage.cpp:56:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
                        ^
voltage.cpp:59:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&a,&b);
                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...