链表存图 数据待加强
Description
给定n个点, m条单向
n<=10000, m <= 100000
有k个询问,询问x出去的所有边
由于没有配置SPJ,输出边的顺序按照加边的顺序倒着输出,具体见样例
Input
Output
Sample Input
4 5
1 2 5
1 3 4
2 4 3
1 4 8
1 1 10
2
1
2
Sample Output
1->1:10
1->4:8
1->3:4
1->2:5
2->4:3
HINT
Source
//
// b.cpp
// noip
//
// Created by lijian3256 on 2019/12/21.
// Copyright © 2019 lijian3256. All rights reserved.
//
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
int n, m;
int h[1001], cnt;
int nxt[100001], val[100001], zd[100001];
void addedge(int a, int b, int c) {
cnt ++;
val[cnt] = c, zd[cnt] = b;
nxt[cnt] = nxt[ h[a] ];
nxt[h[a]] = cnt;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i ++) {
h[i] = i;
}
cnt = n;
memset(nxt, 0, sizeof(nxt));
for (int i = 1; i <= m; i ++) {
int a, b, c;
cin >> a >> b >> c;
addedge(a, b, c);//a->b:c
// addedge(b, c, a);
}
int k;
cin >> k;
for (int i = 1; i <= k; i ++) {
int x;
cin >> x;
for (int p = nxt[h[x]]; p != 0; p = nxt[p]) {
printf("%d->%d:%d\n", x, zd[p], val[p]);
}
}
return 0;
}
/**************************************************************
Problem: 2428
User: LJA001162
Language: C++
Result: 正确
Time:0 ms
Memory:2712 kb
****************************************************************/