답안 #46451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
46451 2018-04-20T22:03:28 Z alex99 Pipes (CEOI15_pipes) C++14
100 / 100
4220 ms 7672 KB
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;
int N, M;
int TT[100005], R[100005];
long long Sum[100005];
vector <int> G[100005];
bool Use[100005];
void Unite(int x, int y)
{
    if(x == y)
        return;
    if(R[x] < R[y])
    {
        TT[x] = y;
    }
    else
        TT[y] = x;
    if(R[x] == R[y])
        R[x]++;
}

int Father(int x)
{
    int init = x;
    while(x != TT[x])
        x = TT[x];
    while(init != x)
    {
        int next = TT[init];
        TT[init] = x;
        init = next;
    }
    return init;
}

void DFS(int node, int father)
{
    Use[node] = 1;
    for(int i = 0; i < G[node].size(); i++)
    {
        int neighb = G[node][i];
        if(neighb == father)
            continue;
        DFS(neighb, node);
        Sum[node] += Sum[neighb];
    }
    if(Sum[node] == 0 && father != 0)
    {
        cout << node << " " << father << "\n";
    }
}

void Solve()
{
    cin >> N >> M;
    for(int i = 1; i <= N; i++)
        TT[i] = i;
    for(int i = 1; i <= M; i++)
    {
        int x, y;
        cin >> x >> y;
        if(Father(x) == Father(y))
        {
            int r = rand();
            Sum[x] += r;
            Sum[y] -= r;
        }
        else
        {
            G[x].push_back(y);
            G[y].push_back(x);
            Unite(Father(x), Father(y));
        }
    }
    for(int i = 1; i <= N; i++)
        if(Use[i] == 0)
            DFS(i, 0);
}
int main()
{
    srand(time(NULL));
    Solve();
    return 0;
}

Compilation message

pipes.cpp: In function 'void DFS(int, int)':
pipes.cpp:42:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < G[node].size(); i++)
                    ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 2984 KB Output is correct
2 Correct 10 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 298 ms 2888 KB Output is correct
2 Correct 288 ms 2884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 512 ms 3176 KB Output is correct
2 Correct 615 ms 3168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 858 ms 3836 KB Output is correct
2 Correct 829 ms 4096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1237 ms 6020 KB Output is correct
2 Correct 994 ms 6008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1851 ms 6600 KB Output is correct
2 Correct 1821 ms 6516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2536 ms 7452 KB Output is correct
2 Correct 2444 ms 7540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3070 ms 7388 KB Output is correct
2 Correct 3120 ms 7412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4220 ms 7216 KB Output is correct
2 Correct 3614 ms 7672 KB Output is correct