# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
146702 |
2019-08-25T11:48:42 Z |
MvC |
Pipes (CEOI15_pipes) |
C++11 |
|
1515 ms |
43768 KB |
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
//#include "boxes.h"
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int n,m,i,x,y,p[nmax],p1[nmax],sz[nmax],sz1[nmax],fup[nmax],fin[nmax],tin;
vector<pair<int,int> >a[nmax];
int fnd(int x)
{
if(p[x]==x)return x;
return p[x]=fnd(p[x]);
}
void uni(int x,int y)
{
a[x].pb(mkp(y,++tin));
a[y].pb(mkp(x,tin));
x=fnd(x),y=fnd(y);
if(sz[x]<sz[y])swap(x,y);
sz[x]+=sz[y];
p[y]=x;
}
int fnd1(int x)
{
if(p1[x]==x)return x;
return p1[x]=fnd1(p1[x]);
}
void uni1(int x,int y)
{
a[x].pb(mkp(y,++tin));
a[y].pb(mkp(x,tin));
x=fnd1(x),y=fnd1(y);
if(sz1[x]<sz1[y])swap(x,y);
sz1[x]+=sz1[y];
p1[y]=x;
}
void dfs(int x,int pr=-1)
{
fin[x]=fup[x]=++tin;
for(int i=0;i<a[x].size();i++)
{
int y=a[x][i].fr;
if(a[x][i].sc==pr)continue;
if(!fin[y])
{
dfs(y,a[x][i].sc);
fup[x]=min(fup[x],fup[y]);
if(fup[y]>fin[x])cout<<x<<" "<<y<<'\n';
}
else fup[x]=min(fup[x],fin[y]);
}
}
int main()
{
//freopen("sol.in","r",stdin);
//freopen("sol.out","w",stdout);
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
cin>>n>>m;
for(i=1;i<=n;i++)
{
p[i]=i;
sz[i]=1;
p1[i]=i;
sz1[i]=1;
}
while(m--)
{
cin>>x>>y;
if(fnd(x)!=fnd(y))
{
uni(x,y);
//cout<<x<<" "<<y<<endl;
}
else if(fnd1(x)!=fnd1(y))
{
uni1(x,y);
//cout<<x<<" "<<y<<endl;
}
}
//cout<<endl;
for(i=1;i<=n;i++)
{
if(fin[i])continue;
dfs(i);
}
return 0;
}
Compilation message
pipes.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("O3")
pipes.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("unroll-loops")
pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:55:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<a[x].size();i++)
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2680 KB |
Output is correct |
2 |
Correct |
3 ms |
2680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
3320 KB |
Output is correct |
2 |
Correct |
9 ms |
3036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
3200 KB |
Output is correct |
2 |
Correct |
124 ms |
3192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
211 ms |
4024 KB |
Output is correct |
2 |
Correct |
247 ms |
14868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
370 ms |
6104 KB |
Output is correct |
2 |
Runtime error |
312 ms |
19588 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
507 ms |
12612 KB |
Output is correct |
2 |
Runtime error |
441 ms |
27388 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
770 ms |
14048 KB |
Output is correct |
2 |
Runtime error |
739 ms |
43768 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1012 ms |
16764 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1244 ms |
21388 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1515 ms |
33720 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |