Pagini recente » Cod sursa (job #3149215) | Cod sursa (job #317149) | Cod sursa (job #3142436) | Cod sursa (job #1198593) | Cod sursa (job #2724015)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("felinare.in");
ofstream fout("felinare.out");
int n, m, din[10000], dout[10000], ans[10000];
vector<int> g[10000], gt[10000];
int main() {
fin >> n >> m;
while(m--) {
int u, v;
fin >> u >> v;
g[u].push_back(v);
gt[v].push_back(u);
dout[u]++;
din[v]++;
}
vector<pair<pair<int, int>, int> > v;
for(int i = 1; i <= n; i++) {
v.push_back({{din[i], 2}, i});
v.push_back({{dout[i], 1}, i});
}
sort(v.begin(), v.end());
int nr = 0;
for(auto x: v) {
cout << x.first.first << ' ' << x.first.second << ' ' <<x.second << '\n';
int node = x.second;
int t = x.first.second;
bool ok = true;
if(t == 1) {
for(auto next: g[node]) {
if(ans[next] / 2)
ok = false;
}
} else {
for(auto next: gt[node]) {
if(ans[next] % 2)
ok = false;
}
}
if(ok) {
nr++;
ans[node] += t;
cout << "good\n";
}
}
fout << nr << '\n';
for(int i = 1; i <= n; i++)
fout << ans[i] << '\n';
}