Submission #244465

# Submission time Handle Problem Language Result Execution time Memory
244465 2020-07-04T06:36:15 Z SomeoneUnknown Potemkin cycle (CEOI15_indcyc) C++14
30 / 100
36 ms 3576 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> adjlist[1001];

/*bool isadj(int a, int b){
    int lo = -1;
    int hi = adjlist[a].size();
    while(hi-lo > 1){
        int mid = (hi+lo)/2;
        if(adjlist[a][mid] == b) return true;
        if(adjlist[a][mid] < b){
            lo = mid;
        }else{
            hi = mid;
        }
    }
    return false;
}*/
int main(){
    int n, r;
    scanf("%d %d", &n, &r);
    int ved[n+1];
    bool isadj[n+1][n+1];
    for(int i = 1; i <= n; ++i){
        ved[i] = 0; //unvisited
        for(int j = 1; j <= n; ++j){
            isadj[i][j] = false;
        }
        isadj[i][i] = true;
    }
    for(int i = 0; i < r; ++i){
        int a, b;
        scanf("%d %d", &a, &b);
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
        isadj[a][b] = true;
        isadj[b][a] = true;
    }
    for(int i = 1; i <= n; ++i){
        sort(adjlist[i].begin(), adjlist[i].end());
    }
    for(int i = 1; i <= n; ++i){
        if(ved[i] != 0) continue;
        ved[i] = -1; //root
        queue<int> tovisit;
        tovisit.push(i);
        while(!tovisit.empty()){
            int ving = tovisit.front();
            //printf("ving = %d\n", ving);
            tovisit.pop();
            for(int j = 0; j < adjlist[ving].size(); ++j){
                int nghbr = adjlist[ving][j];
                if(ved[nghbr] == 0){
                    ved[nghbr] = ving;
                    tovisit.push(nghbr);
                }else{
                    if(ved[ving] == nghbr) continue;
                    if(ved[nghbr] < 1) return -1;
                    if(isadj[ved[nghbr]][ving]) continue;
                    stack<int> s;
                    queue<int> e;
                    //s.push(ving);
                    //e.push(nghbr);
                    int last;
                    int sptr = ving;
                    int eptr = nghbr;
                    while(sptr != eptr){
                        e.push(eptr);
                        //printf("e: %d\n", eptr);
                        last = eptr;
                        eptr = ved[eptr];

                        if(sptr == eptr) break;
                        s.push(sptr);
                        //printf("s: %d\n", sptr);
                        sptr = ved[sptr];
                    }
                    //return 5; //doesnt reach
                    bool djoint = true;
                    for(int k = 0; k < adjlist[s.top()].size(); k++){
                        if(adjlist[s.top()][k] == last) djoint = false;
                    }
                    if(djoint)
                        printf("%d ", sptr);
                    while(!s.empty()){
                        printf("%d ", s.top());
                        s.pop();
                    }
                    while(!e.empty()){
                        printf("%d ", e.front());
                        e.pop();
                    }
                    return 0;
                }
            }
        }
    }
    printf("no");
}
/*
5 5
1 2
2 3
2 4
3 5
4 5
*/

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:52:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j = 0; j < adjlist[ving].size(); ++j){
                            ~~^~~~~~~~~~~~~~~~~~~~~~
indcyc.cpp:81:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     for(int k = 0; k < adjlist[s.top()].size(); k++){
                                    ~~^~~~~~~~~~~~~~~~~~~~~~~~~
indcyc.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &r);
     ~~~~~^~~~~~~~~~~~~~~~~
indcyc.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~
indcyc.cpp:82:25: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
                         if(adjlist[s.top()][k] == last) djoint = false;
                         ^~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Integer 0 violates the range [1, 100]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 512 KB Wrong answer on graph without induced cycle
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 512 KB Integer 0 violates the range [1, 300]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 25 ms 3576 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 3072 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 1536 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -