답안 #146322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
146322 2019-08-23T13:06:25 Z evpipis Pipes (CEOI15_pipes) C++
20 / 100
1839 ms 14012 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;

const int len = 1e5+3;
int n, m, cnt;
int par[len], num[len], low[len];
vector<int> adj[len];
vector<ii> vec;

struct dsu{
    int anc[len];

    void init(){
        for (int i = 1; i <= n; i++)
            anc[i] = i;
    }

    int fin(int i){
        if (anc[i] == i) return i;
        return anc[i] = fin(anc[i]);
    }

    void join(int i, int j){
        i = fin(i), j = fin(j);
        if (i != j)
            anc[j] = i;
    }
};

dsu one, two;

void dfs(int u){
    num[u] = low[u] = ++cnt;
    for (int j = 0; j < adj[u].size(); j++){
        int v = adj[u][j];
        if (!num[v]){
            par[v] = u;
            dfs(v);

            if (low[v] > num[u])
                printf("%d %d\n", u, v);
            low[u] = min(low[u], low[v]);
        }
        else if (v != par[u]){
            low[u] = min(low[u], num[v]);
        }
    }
}

int main(){
    scanf("%d %d", &n, &m);
    one.init();
    two.init();
    for (int i = 0; i < m; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        if (one.fin(a) != one.fin(b)){
            vec.pb(mp(a, b));
            one.join(a, b);
        }
        else if (two.fin(a) != two.fin(b)){
            vec.pb(mp(a, b));
            two.join(a, b);
        }
    }

    for (int i = 0; i < vec.size(); i++){
        int a = vec[i].fi, b = vec[i].se;
        adj[a].pb(b);
        adj[b].pb(a);
    }

    for (int i = 1; i <= n; i++)
        if (!num[i])
            dfs(i);
    return 0;
}

Compilation message

pipes.cpp: In function 'void dfs(int)':
pipes.cpp:40:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j < adj[u].size(); j++){
                     ~~^~~~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:73:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.size(); i++){
                     ~~^~~~~~~~~~~~
pipes.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:62: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 4 ms 2680 KB Output is correct
2 Incorrect 4 ms 2680 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 3192 KB Output is correct
2 Incorrect 9 ms 3064 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 3064 KB Output is correct
2 Incorrect 136 ms 3064 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Incorrect 247 ms 3832 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 417 ms 5448 KB Output is correct
2 Correct 529 ms 5272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 577 ms 10752 KB Output is correct
2 Incorrect 501 ms 8424 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 883 ms 11792 KB Output is correct
2 Incorrect 942 ms 9356 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 1224 ms 14008 KB Output is correct
2 Incorrect 1105 ms 10764 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 1465 ms 14012 KB Output is correct
2 Incorrect 1369 ms 10804 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 1755 ms 13500 KB Output is correct
2 Correct 1839 ms 11340 KB Output is correct