답안 #591613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
591613 2022-07-07T16:55:42 Z andrei_boaca Pipes (CEOI15_pipes) C++14
40 / 100
4450 ms 65536 KB
#include <bits/stdc++.h>

using namespace std;
typedef pair<int,int> pii;
int n,m;
vector<vector<unsigned short>> muchii;
vector<vector<short>> bits;
bool use[100005];
int par[100005];
int niv[100005],nivmin[100005];
void add(int a,int b)
{
    if(muchii[a].size()%15==0)
    {
        short x=0;
        bits[a].push_back(x);
    }
    int val=bits[a].back();
    if((b>>16)&1)
    {
        int nrbit=muchii[a].size()%15;
        val+=(1<<nrbit);
        bits[a].back()=val;
        b-=(1<<16);
    }
    muchii[a].push_back(b);
}
int getnum(int a,int poz)
{
    int x=muchii[a][poz];
    int grup=poz/15;
    int bit=poz%15;
    if((bits[a][grup]>>bit&1))
        x+=(1<<16);
    return x;
}
void dfs(int nod)
{
    use[nod]=1;
    nivmin[nod]=niv[nod];
    for(int i=0;i<muchii[nod].size();i++)
    {
        int node=getnum(nod,i);
        if(node==par[nod])
            continue;
        if(!use[node])
        {
            par[node]=nod;
            niv[node]=niv[nod]+1;
            dfs(node);
            nivmin[nod]=min(nivmin[nod],nivmin[node]);
        }
        else
            nivmin[nod]=min(nivmin[nod],niv[node]);
    }
    int cnt=0;
    if(nivmin[nod]==niv[nod]&&par[nod]!=0)
    {
        for(int i=0;i<muchii[nod].size();i++)
        {
            int x=getnum(nod,i);
            if(x==par[nod])
                cnt++;
        }
        if(cnt==1)
            cout<<par[nod]<<' '<<nod<<'\n';
    }
}
int main()
{
    cin>>n>>m;
    muchii.resize(n+1);
    bits.resize(n+1);
    for(int i=1;i<=m;i++)
    {
        int a,b;
        cin>>a>>b;
        add(b,a);
        add(a,b);
    }
    for(int i=1;i<=n;i++)
        if(!use[i])
        {
            niv[i]=1;
            dfs(i);
        }
    return 0;
}

Compilation message

pipes.cpp: In function 'void dfs(int)':
pipes.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<short unsigned int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i=0;i<muchii[nod].size();i++)
      |                 ~^~~~~~~~~~~~~~~~~~~
pipes.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<short unsigned int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for(int i=0;i<muchii[nod].size();i++)
      |                     ~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1236 KB Output is correct
2 Correct 8 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 273 ms 6920 KB Output is correct
2 Correct 311 ms 6496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 502 ms 9760 KB Output is correct
2 Correct 582 ms 11624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 865 ms 17432 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1295 ms 28788 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2088 ms 40768 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2885 ms 61644 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3636 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4450 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -