[Offer收割]编程练习赛98 register

Ended

Participants:89

Verdict:Accepted
Score:100 / 100
Submitted:2019-03-31 12:46:43

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<bits/stdc++.h>
using namespace std;
struct node {
    int v,p;
} n[1001];
set<int>S[1001];
set<int>::iterator it;
int A[1001][1001],T[1001],F[1001];
bool K[1001];
bool cmp(node x,node y) {
    return x.v<y.v;
}
int main() {
    int a,b,i,j,x,y;
    cin>>a>>b;
    for(i=1; i<=a; i++)n[i].p=i;
    for(i=1; i<=b; i++)scanf("%d%d",&x,&y),S[x].insert(y),n[x].v++,A[y][++T[y]]=x;
    sort(n+1,n+a+1,cmp);
    for(i=1; i<=a; i++) {
        int p=n[i].p;
        for(it=S[p].begin(); it!=S[p].end(); it++) {
            F[*it]=p;
            for(j=1; j<=T[p]; j++)S[A[p][j]].erase(*it);
        }
    }
    for(i=1; i<=a; i++)cout<<F[i]<<endl;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX