답안 #581786

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

using namespace std;

typedef long long ll;

int n, m;
vector<pair<int, int> > link[200002];
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;
        visited[y.second] = 0;
    }
    cycle.pop_back();
    vv[x]=0;
    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));
    }
    assert(findCycle(1));
    cycle.erase(cycle.begin(), find(cycle.begin(), cycle.end(), cycle.back())+1);
    int len = (int)cycle.size();
    if(len%2) ans = len;
    else ans = n-len;
    printf("%d", ans);
}

Compilation message

voltage.cpp: In function 'int main()':
voltage.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
voltage.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 5088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 9032 KB Output is correct
2 Correct 72 ms 13164 KB Output is correct
3 Correct 52 ms 9040 KB Output is correct
4 Correct 68 ms 15100 KB Output is correct
5 Correct 8 ms 5784 KB Output is correct
6 Correct 52 ms 11768 KB Output is correct
7 Correct 63 ms 16840 KB Output is correct
8 Correct 83 ms 16924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 42 ms 18312 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 58 ms 10176 KB Output isn't correct
2 Halted 0 ms 0 KB -