这题的dp里的check里的函数要考虑k control i control j和i control j control k的情况
/* ID: yingzho1 LANG: C++ TASK: concom */ #include <iostream> #include <fstream> #include <string> #include <map> #include <vector> #include <set> #include <algorithm> #include <stdio.h> #include <queue> #include <cstring> #include <cmath> using namespace std; ifstream fin("concom.in"); ofstream fout("concom.out"); int N; ][]; ][]; void check(int i, int j) { c[i][j] = true; //cout << "c[" << i << "][" << j << "] = true" << endl; ; k <= ; k++) d[i][k] += d[j][k]; ; k <= ; k++) ) check(i, k); ; k <= ; k++) if (c[k][i] && !c[k][j]) check(k, j); } int main() { fin >> N; ; i < N; i++) { int a, b, c; fin >> a >> b >> c; d[a][b] = c; } ; i <= ; i++) c[i][i] = ; ; i <= ; i++) { ; j <= ; j++) { ) check(i, j); } } ; i <= ; i++) { ; j <= ; j++) { if (i != j && c[i][j]) fout << i << " " << j << endl; } } ; }