#include <bits/stdc++.h>
using namespace std;
int n, m, cnt = 0;
struct {
int to, w1, w2, next;
}edge[100];
int head[100];
void init(){
memset(head, -1, sizeof(head));
}
void add_edge(int u, int v,int w1, int w2){
edge[cnt].to = v;
edge[cnt].w1 = w1;
edge[cnt].w2 = w2;
edge[cnt].next = head[u];
head[u] = cnt ++;
}
int main() {
cin >> n >> m;
int u, v, w1, w2;
for(int i = 1;i <= m;i ++){
cin >> u >> v >> w1 >> w2;
add_edge(u, v, w1, w2);
}
for(int i = 1;i <= n;i ++){
cout << i << endl;
for(int j = head[i];j != -1;j = edge[j].next){
cout << i << ' ' << edge[j].to << ' ' <<edge[j].w1 << ' ' << edge[j].w2 << endl;
}
cout << endl;
}
}
如图,这是我写的链式前向星,w1
和w2
是题目要用的两个不同的价值
问题在于输入数据后会无限输出,请问哪里有问题啊QAQ
数据在这里:
3 3
1 3 1 2
1 2 1 2
2 3 1 2