답안 #244552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
244552 2020-07-04T09:35:33 Z tqbfjotld Pipes (CEOI15_pipes) C++14
30 / 100
312 ms 9848 KB
///lib code still allowed right
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

#define MAXN 10005

int low[MAXN];
int order[MAXN];
int cur = 1;
pair<int,int> edgelist[1200005];
int root = 0;
int temp[MAXN];
int n,e;

///ensure no duplicate edges first though
void dfs(int node, int parent){
    order[node] = cur;
    cur++;
    low[node] = order[node];
    for (auto it = lower_bound(edgelist,edgelist+2*e,make_pair(node,-1)); it!=edgelist+2*e && (*it).first==node; it++){
        temp[(*it).second]++;
    }
    for (auto it = lower_bound(edgelist,edgelist+2*e,make_pair(node,-1)); it!=edgelist+2*e && (*it).first==node; it++){
        if (temp[(*it).second]==0) continue;
        temp[(*it).second]--;
        bool thing = false;
        if (temp[(*it).second]!=0) {
            thing = true;
            temp[(*it).second] = 0;
        }
        if (order[(*it).second]==-1){
            dfs((*it).second,thing?-1:node);
            if (low[node]==-1 || (low[(*it).second]!=-1 && low[(*it).second]<low[node])){
                low[node] = low[(*it).second];
            }
            if (node!=root){
                if (low[(*it).second]==-1 || low[(*it).second]>=order[node]){
                }
            }
            else{
            }
        }
        else if ((*it).second!=parent){
            if (low[node]==-1 || order[(*it).second]<low[node]) low[node] = order[(*it).second];
        }
    }
}
//ans is number of components after removing node (>1 if is articulation point)
//bridge break a component if it is removed
//HAVE NOT TESTED YET (but should be correct though)
inline bool isBridge(int a, int b){
    if (order[b]<order[a]) swap(a,b);
    return low[b]>order[a];
}



int main(){
    scanf("%d%d",&n,&e);
    for (int x = 0; x<e; x++){
        int a,b;
        scanf("%d%d",&a,&b);
        a--;b--;
        edgelist[x*2] = {a,b};
        edgelist[x*2+1] = {b,a};
    }
    sort(edgelist,edgelist+e*2);
    memset(low,-1,sizeof(low));
    memset(order,-1,sizeof(order));
    for (root = 0; root<n; root++){
        if (order[root]==-1) dfs(root,-1);
    }
    for (int x = 0; x<n; x++){
        //printf("%d: order: %d, low: %d\n",1+x,order[x],low[x]);
    }
    for (int i = 0; i<2*e; i++){
            int x = edgelist[i].first;
            int y = edgelist[i].second;
            if (y<x){
                if (isBridge(x,y)){
                    printf("%d %d\n",x+1,y+1);
                }
            }
    }

}



Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&e);
     ~~~~~^~~~~~~~~~~~~~
pipes.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&a,&b);
         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 768 KB Output is correct
2 Correct 11 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 312 ms 9848 KB Output is correct
2 Correct 306 ms 9656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 163 ms 9720 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 175 ms 9848 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 170 ms 9824 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 173 ms 9848 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 171 ms 9720 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 179 ms 9720 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 178 ms 9704 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -