| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1353613 | sally | PPP (EGOI23_ppp) | C++20 | 0 ms | 0 KiB |
// https://oj.uz/problem/view/EGOI23_ppp
#include<iostream>
#include<vector>
using namespace std;
typedef pair<int,int> pii;
vector<int> ans;
vector<vector<int>> g;
vector<pii> event;
vector<int> match, cnt;
void dfs(int now, int pre, int MAXN, int MAX) {
for(int i: g[now]) {
cout<<now<<' '<<i<<'\n';
int win = event[i].first;
cnt[win] += (now - i); // 持有天數+1
int mxn = MAXN, mx = MAX;
if(cnt[win] > mxn) {mxn = cnt[win]; mx = win;}
else if(cnt[win] == mxn) mx = min(mx, win);
ans[mx]++;
dfs(i, now, mxn, mx);
cnt[win] -= (now - i);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, M;
cin>>N>>M;
g.resize(M+2);
ans.assign(N+2, 0);
cnt.assign(N+2, 0);
event.resize(M+2);
match.assign(M+2, -1);
for(int i=1; i<=M; i++) {
int win, lose;
cin>>win>>lose;
event[i].first = win;
event[i].second = lose;
if(match[win]!=-1) {g[i].push_back(match[win]); p[match[win]] = i;}
if(match[lose]!=-1) {g[i].push_back(match[lose]); p[match[lose]] = i;}
match[win] = i;
match[lose] = -1;
}
for(int i=1; i<=M; i++)
if(p[i] == -1) g[M+1].push_back(i); // fake node
dfs(M+1, M+1, 0, N+1);
for(int i=0; i<N; i++) cout<<ans[i]<<' ';
}