| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 782606 | christinelynn | Naboj (COCI22_naboj) | C++17 | 175 ms | 21068 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define endl "\n"
#define pii pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define pque priority_queue
#define pqueg priority_queue<ll,vector<ll>,greater<ll>>
#define que queue<ll>
#define FOR(m,i,n) for(int i=(m); i<=(n); i++)
#define FORM(m,i,n) for(int i=(m); i>=(n); i--)
ll n,m,u,v;
bool vis[200200];
vector<ll> adj[200200],ans;
ll top[200200];
queue<ll> q;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
FOR(1,i,m) {
cin >> u >> v;
adj[v].pb(u);
top[u]++;
}
FOR(1,i,n) {
if(top[i] == 0) {
q.push(i);
vis[i] = true;
ans.pb(i);
}
}
while(!q.empty()) {
ll x = q.front();
q.pop();
for(auto i : adj[x]) {
if(!vis[i]) {
top[i]--;
if(top[i] == 0) {
vis[i] = true;
ans.pb(i);
q.push(i);
}
}
}
}
if(ans.size() != n) {
cout << -1 << endl;
return 0;
}
cout << n << endl;
for(auto i : ans) {
cout << i << " 1" << endl;
}
}
/*
5 5
3 1
2 3
4 2
5 2
5 4
*/컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
