답안 #129874

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
129874 2019-07-13T12:29:31 Z KOMJ01 산만한 고양이 (KOI17_cat) C++14
0 / 100
2000 ms 46480 KB
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int b1;
int cycle(int a, int b2);
vector<vector<int>> v;
vector<int> v2;
vector<int> cnt;
int main()
{
    int n,m,a,b,t=0, i;
    cin >> n >> m;

    v.resize(n);
    v2.resize(n);
    cnt.resize(n);
    for(i=0;i<n;++i){
        v2.at(i)=0;
    }
    for(i=0; i<m; ++i)
    {
        cin >> a >> b;
        v.at(a-1).push_back(b-1);
        v.at(b-1).push_back(a-1);
    }
    b1=0;
    int temp1, temp2;
    temp1=cycle(1,-1);
    for(i=0; i<n;++i)
    {
        if(cnt.at(i)==0){temp2=cycle(i,-1);break;}
    }
    if(temp1==0 && temp2==0){++t;}
    for(i=1;i<n;++i)
    {
        for(int j=0;j<n;++j){
            v2.at(j)=0;
        }
        for(int j=0;j<n;++j){
            cnt.at(j)=0;
        }
        b1=i;
        temp1=cycle(0,-1);
        for(int j=0; j<n;++j)
        {
            if(cnt.at(j)==0){temp2=cycle(j,-1);break;}
        }
        if(temp1==0 && temp2==0){t+=i+1;}
    }   
    cout <<t;
}

int cycle(int a,int b2)
{

    v2.at(a)=1;
    cnt.at(a)=1;
    int k;
    for(int i=0;i<v.at(a).size();++i){
        k=v.at(a).at(i); 
        //cout << k << " ";
        if(k==b1||k==b2){
            //cout << k << " continue" << endl;
            continue;
        }
        else if(v2.at(k)==1){
            //cout << "find cycle" << endl;
            return 1;
        }
       // cout<< v.at(a).at(i) << " ";//<< endl;
        if(cycle(v.at(a).at(i), a))return 1;
    }
    v2.at(a)=0;
    return 0;
}

Compilation message

cat.cpp: In function 'int cycle(int, int)':
cat.cpp:62:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v.at(a).size();++i){
                 ~^~~~~~~~~~~~~~~
cat.cpp: In function 'int main()':
cat.cpp:36:17: warning: 'temp2' may be used uninitialized in this function [-Wmaybe-uninitialized]
     if(temp1==0 && temp2==0){++t;}
        ~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 1263 ms 1016 KB Output is correct
6 Correct 288 ms 888 KB Output is correct
7 Correct 927 ms 988 KB Output is correct
8 Incorrect 771 ms 860 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2048 ms 23384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2040 ms 46480 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 1263 ms 1016 KB Output is correct
6 Correct 288 ms 888 KB Output is correct
7 Correct 927 ms 988 KB Output is correct
8 Incorrect 771 ms 860 KB Output isn't correct
9 Halted 0 ms 0 KB -