QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#44720 | #995. 桥 | do_while_true# | RE | 0ms | 0kb | C++ | 2.2kb | 2022-08-21 11:40:18 | 2022-08-21 11:40:21 |
Judging History
answer
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<random>
#include<assert.h>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n';
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n';
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pil>vpil;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
r=0;bool w=0;char ch=getchar();
while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int N=100010;
int n,m,vis[N],dep[N];
int treg[N];
vpii eg[N];
int eu[N],ev[N],c[N];
void dfs1(int x){
vis[x]=1;
for(auto i:eg[x]){
int v=i.fi,id=i.se;
if(vis[v])continue;
treg[id]=1;
dep[v]=dep[x]+1;
dfs1(v);
}
}
void dfs2(int x){
vis[x]=1;
for(auto i:eg[x]){
int v=i.fi;
if(vis[v])continue;
dfs2(v);
c[x]+=c[v];
}
}
signed main(){
#ifdef do_while_true
// assert(freopen("data.in","r",stdin));
// assert(freopen("data.out","w",stdout));
#endif
read(n,m);
for(int i=1,u,v;i<=m;i++){
read(u,v);eu[i]=u;ev[i]=v;
eg[u].pb(mp(v,i));eg[v].pb(mp(u,i));
}
dfs1(1);
for(int i=1;i<=m;i++){
if(treg[i])continue;
int u=eu[i],v=ev[i];
if(dep[u]>dep[v])swap(u,v);
c[u]--;c[v]++;
}
for(int i=1;i<=n;i++)vis[i]=0;
dfs2(1);
for(int i=1;i<=m;i++){
int u=eu[i],v=ev[i];
if(abs(dep[u]-dep[v])!=1)continue;
if(dep[u]>dep[v])swap(u,v);
if(c[v]==0)cout << u << ' ' << v << '\n';
}
#ifdef do_while_true
cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
24942 387166 12556 21443 22404 16376 11073 24296 1535 11968 23745 2818 5073 12731 22550 14761 24118 12008 22695 18979 15118 13639 2080 8721 692 22578 22581 15267 9278 4127 7457 21674 17693 23448 10949 23429 9700 6009 14140 5064 7742 15164 17336 1662 18903 9760 17645 19575 6540 11942 11 4937 15282 10...