Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- #define forn(i, n) for (int i = 0; i < (n); i++)
- const int INF = 1000 * 1000 * 1000;
- int a[100][100];
- int main () {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int n;
- cin >> n;
- forn (i, n) {
- forn (j, n) {
- cin >> a[i][j];
- if (a[i][j] == 0) {
- a[i][j] = INF;
- }
- if (a[i][i] > 0)
- a[i][i] = 0;
- }
- }
- forn(k, n)
- forn(i, n)
- forn(j, n)
- if (a[i][k] < INF && a[k][j] < INF)
- a[i][j] =
- min(a[i][j], (1ll * a[i][k] + 1ll * a[k][j] < -INF ? -INF : a[i][k] + a[k][j]));
- forn(k, n)
- forn(i, n)
- forn(j, n)
- if (a[i][k] < INF && a[k][k] < 0 && a[k][j] < INF)
- a[i][j] = -INF;
- forn (i, n) {
- forn (j, n) {
- if (a[i][j] == INF)
- cout << 0 << " ";
- else
- if (a[i][j] == -INF)
- cout << 2 << " ";
- else
- cout << 1 << " ";
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement