답안 #804586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
804586 2023-08-03T09:59:37 Z Hanksburger Pipes (CEOI15_pipes) C++17
50 / 100
803 ms 59288 KB
#include <bits/stdc++.h>
using namespace std;
int par[100005][2], tin[100005], low[100005], visited[100005], t;
vector<pair<int, int> > ans;
vector<int> adj[100005];
int findPar(int u, int x)
{
    return (par[u][x]==u?u:par[u][x]=findPar(par[u][x], x));
}
void dfs(int u, int p)
{
    tin[u]=low[u]=(++t);
    visited[u]=1;
    int pass=1;
    for (int v:adj[u])
    {
        if (v==p && pass)
        {
            pass=0;
            continue;
        }
        if (visited[v])
            low[u]=min(low[u], tin[v]);
        else
        {
            dfs(v, u);
            low[u]=min(low[u], low[v]);
            if (low[v]>=tin[v])
                ans.push_back({u, v});
        }
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i=1; i<=n; i++)
        par[i][0]=par[i][1]=i;
    for (int i=1; i<=m; i++)
    {
        int u, v, U, V;
        cin >> u >> v;
        if (findPar(u, 0)!=findPar(v, 0))
        {
            par[par[u][0]][0]=par[v][0];
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        else if (findPar(u, 1)!=findPar(v, 1))
        {
            par[par[u][1]][1]=par[v][1];
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
    }
    for (int i=1; i<=n; i++)
        if (!visited[i])
            dfs(i, 0);
    for (int i=0; i<ans.size(); i++)
        cout << ans[i].first << ' ' << ans[i].second << '\n';
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:44:19: warning: unused variable 'U' [-Wunused-variable]
   44 |         int u, v, U, V;
      |                   ^
pipes.cpp:44:22: warning: unused variable 'V' [-Wunused-variable]
   44 |         int u, v, U, V;
      |                      ^
pipes.cpp:62:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for (int i=0; i<ans.size(); i++)
      |                   ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3156 KB Output is correct
2 Correct 5 ms 2980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 3020 KB Output is correct
2 Correct 67 ms 2824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 3788 KB Output is correct
2 Correct 126 ms 3256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 190 ms 5600 KB Output is correct
2 Correct 158 ms 5264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 286 ms 11540 KB Output is correct
2 Runtime error 243 ms 25692 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 404 ms 20872 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 561 ms 36660 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 663 ms 47916 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 803 ms 59288 KB Memory limit exceeded
2 Halted 0 ms 0 KB -