답안 #581776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581776 2022-06-23T06:09:26 Z 반딧불(#8365) 전압 (JOI14_voltage) C++14
0 / 100
49 ms 15132 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, m;
vector<pair<int, int> > link[100002];
int ex[100002], ey[100002];
int ans;

bool vv[200002];
bool visited[200002];
vector<int> cycle;
bool findCycle(int x){
    cycle.push_back(x);
    if(vv[x]) return true;
    vv[x]=1;
    for(auto y: link[x]){
        if(visited[y.second]) continue;
        visited[y.second] = 1;
        if(findCycle(y.first)) return true;
    }
    cycle.pop_back();
    return false;
}

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;
    }
    assert(findCycle(1));
    cycle.erase(cycle.begin(), find(cycle.begin(), cycle.end(), cycle.back())+1);
    int len = (int)cycle.size();
    if(len%2) ans = n;
    else ans = n-len;
    printf("%d", ans);
}

Compilation message

voltage.cpp: In function 'int main()':
voltage.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
voltage.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 7512 KB Output is correct
2 Correct 49 ms 10832 KB Output is correct
3 Incorrect 37 ms 7628 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 15132 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 30 ms 14652 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -