# 14180: 【原4180】混合图定向

### 题目描述

author: Konpaku 原OJ链接：https://acm.sjtu.edu.cn/OnlineJudge-old/problem/4180

## Sample Input

``````4 2 3
1 2
4 3
1 3
4 2
3 2
``````

## Sample Output

``````1 3
4 2
2 3
``````

## zqy2018's solution

``````#include <bits/stdc++.h>
#define REP(temp, init_val, end_val) for (int temp = init_val; temp <= end_val; ++temp)
#define REPR(temp, init_val, end_val) for (int temp = init_val; temp >= end_val; --temp)
using namespace std;
int f = 1, x = 0;
char c = getchar();
while (c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
while (c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
return f * x;
}
int to[100005], nxt[100005], at[100005] = {0}, cnt = 0;
int fr[100005], to2[100005];
int dir[100005] = {0}, du[100005] = {0}, rk[100005] = {0};
int n, m1, m2;
queue<int> q;
void init(){
REP(i, 1, m1){
to[++cnt] = v, nxt[cnt] = at[u], at[u] = cnt;
++du[v];
}
REP(i, 1, m2)
}
void solve(){
REP(i, 1, n){
if (!du[i])
q.push(i);
}
REP(i, 1, n){
int h = q.front();
q.pop();
rk[h] = i;
for (int i = at[h]; i; i = nxt[i]){
int v = to[i];
--du[v];
if (!du[v]) q.push(v);
}
}
REP(i, 1, m2){
if (rk[fr[i]] < rk[to2[i]])
printf("%d %d\n", fr[i], to2[i]);
else
printf("%d %d\n", to2[i], fr[i]);
}
}
int main(){
init();
solve();
return 0;
}
``````