Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #define DMAX 210
- using namespace std;
- ifstream fin("partial.in");
- ofstream fout("partial.out");
- int n, a, b, elim, ic, sc, C[DMAX], newM[DMAX][DMAX];
- bool M[DMAX][DMAX], viz[DMAX];
- int main()
- {
- int i, j, acum;
- fin >> n;
- while (fin >> a >> b)
- M[a][b] = M[b][a] = 1;
- for (i = 1; i <= n; i++)
- {
- for (j = i + 1; j <= n; j++)
- {
- if (M[i][j])
- elim++;
- }
- }
- elim /= 2;
- ic = 0;
- sc = -1;
- C[++sc] = 1;
- while (ic <= sc)
- {
- acum = C[ic++];
- for (i = 1; i <= n; i++)
- {
- if (M[acum][i])
- {
- if (!viz[i])
- {
- viz[i] = 1;
- C[++sc] = i;
- newM[acum][i] = newM[i][acum] = 1;
- }
- else
- {
- if (elim && !newM[acum][i])
- {
- elim--;
- newM[acum][i] = newM[i][acum] = -1;
- }
- else if (newM[acum][i] != -1 && newM[i][acum] != -1)
- newM[acum][i] = newM[i][acum] = 1;
- }
- }
- }
- }
- for (i = 1; i <= n; i++)
- {
- for (j = 1; j <= n; j++)
- {
- if (newM[i][j] == -1)
- newM[i][j] = 0;
- fout << newM[i][j] << ' ';
- }
- fout << '\n';
- }
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement