concom

/*
ID: zachery1
PROG: concom
LANG: C++
*/
#include 
#include 
#include 
#include 
#include 
#include 
#define MAXN 110
#define cin fin
#define cout fout
using namespace std;
ifstream fin("concom.in");
ofstream fout("concom.out");

typedef pair<int, int> P;
int a[MAXN][MAXN];
int control[MAXN][MAXN];
int fa[MAXN];
int n;
queue

que; void solve() { while (!que.empty()) { P p = que.front(); int A = p.first; int B = p.second; que.pop(); for (int i = 1; i <= 100; i++) { if (a[B][i] && B != i && A != i) { //cout << "a[" << B << "]" << "[" << i << "] = " << a[B][i] << endl; //cout << "control[" << A << "]" << "[" << i << "] = " << control[A][i] << endl; int old = control[A][i]; control[A][i] += control[B][i]; //cout << "new a[" << A << "]" << "[" << i << "] = " << control[A][i] << endl; if (old <= 50 && control[A][i] > 50) { que.push(P(A, i)); fa[i] = A; } } } } } int main() { cin >> n; memset(a, 0, sizeof(a)); for (int t = 0; t < n; t++) { int i, j, p; cin >> i >> j >> p; a[i][j] = p; control[i][j] = p; if (p > 50) { que.push(P(i, j)); fa[j] = i; } } solve(); for (int i = 1; i <= 100; i++) { for (int j = 1; j <= 100; j++) { if (i != j) { if (control[i][j] > 50) { cout << i << " " << j << endl; } } } } return 0; }

你可能感兴趣的:(USACO)