답안 #143121

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
143121 2019-08-13T05:47:18 Z Ruxandra985 Pipes (CEOI15_pipes) C++14
0 / 100
3121 ms 65540 KB
/// trimit de curiozitate

#include <cstdio>
#include <vector>
#include <set>
#include <deque>
#include <algorithm>
#define DIMN 100005
using namespace std;
int low[DIMN],bicnx,lvl[DIMN];
deque <int> st;
vector <int> v[DIMN];
set <int> sol[DIMN];
int x,f[DIMN];
void dfs2 (int nod,int tt){
    int i,vecin;
    f[nod] = 1;
    for (i=0;i<v[nod].size();i++){
        vecin=v[nod][i];
        if (vecin!=tt && !f[vecin])
            dfs2(vecin,nod);
    }
}
void dfs (int nod,int tt){
    int i,vecin;
    low[nod]=lvl[nod];
    st.push_back(nod);
    for (i=0;i<v[nod].size();i++){
        vecin=v[nod][i];
        if (vecin==tt)
            continue;
        if (lvl[vecin]==0){
            lvl[vecin]=1+lvl[nod];
            dfs(vecin,nod);
            low[nod]=min(low[nod],low[vecin]);
            if (low[vecin]>=lvl[nod]){ // nod e un nod critic
                bicnx++;
                do{
                    x=st.back();
                    st.pop_back();
                    sol[bicnx].insert(x);
                    //printf ("%d %d\n",bicnx , x);
                }
                while (x!=vecin);
                sol[bicnx].insert(nod);
               // printf ("%d %d\n",bicnx , nod);
                // am scos din stiva muchiile care sunt in subarborele nod->vecin
            }
        }
        else low[nod]=min(low[nod],lvl[vecin]);
    }
}
int main()
{
   // freopen ("a.in" , "r" , stdin);
   // freopen ("a.out" , "w" , stdout);
    int n,m,i,x,y;
    scanf ("%d%d",&n,&m);
    for (i=1;i<=m;i++){
        scanf ("%d%d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for (i=1;i<=n;i++){
        if (!f[i]){
            v[0].push_back(i);
            dfs2(i,0);
        }
    }
    dfs (0,0);
    int a,b;
    for (i=1;i<=bicnx;i++){
        if (sol[i].size()==2){
            a = *(sol[i].begin());
            b = *(sol[i].rbegin());
            if (a && b)
                printf ("%d %d\n",a,b);
        }
    }
    return 0;
}

Compilation message

pipes.cpp: In function 'void dfs2(int, int)':
pipes.cpp:18:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<v[nod].size();i++){
              ~^~~~~~~~~~~~~~
pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:28:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<v[nod].size();i++){
              ~^~~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:58:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d%d",&n,&m);
     ~~~~~~^~~~~~~~~~~~~~
pipes.cpp:60:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d%d",&x,&y);
         ~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Incorrect 8 ms 7288 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8056 KB Output is correct
2 Incorrect 14 ms 7932 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 191 ms 15480 KB Output is correct
2 Runtime error 187 ms 20216 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 364 ms 18712 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 723 ms 29432 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1159 ms 35444 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1905 ms 65536 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2504 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2865 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3121 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -