1 条题解
-
0
C++ :
#include <cstdio> /* 有向图邻接表(头插法):邻接顺序 = 输入顺序的逆序。 只输出出度 > 0 的点,按点编号升序。N<=1e5, M<=1e6。 */ static int he[100005], nx[1000005], to[1000005]; int main(){ int n, m; if(scanf("%d %d", &n, &m) != 2) return 0; for(int i = 1; i <= n; i++) he[i] = 0; for(int i = 1; i <= m; i++){ int u, v; if(scanf("%d %d", &u, &v) != 2) break; to[i] = v; nx[i] = he[u]; he[u] = i; } for(int i = 1; i <= n; i++){ if(!he[i]) continue; printf("%d", i); for(int e = he[i]; e; e = nx[e]) printf(" %d", to[e]); putchar('\n'); } return 0; }
- 1
信息
- ID
- 2676
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者