제출 #390287

#제출 시각아이디문제언어결과실행 시간메모리
390287mchangOne-Way Streets (CEOI17_oneway)C++11
100 / 100
112 ms19496 KiB
#define pb push_back #define eb emplace_back #define F first #define S second #include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; vector<pii> adj[1<<18]; char dir[1<<18]; vector<pii> edges; int pre[1<<18]; int link[1<<18]; int prenum = 1; int N,M,P; int indeg[1<<18]; int outdeg[1<<18]; void dfs(int u, int pi) { pre[u] = link[u] = prenum++; int minlink = pre[u]; for (auto& e : adj[u]) { if (e.S == pi) continue; int v = e.F; if (pre[v] == 0) { dfs(v, e.S); indeg[u]+=indeg[v]; outdeg[u]+=outdeg[v]; } minlink = min(minlink, link[v]); } link[u] = minlink; int deg = outdeg[u]-indeg[u]; // if parent edge is part of a bcc, // we don’t care about direction of that edge // we just need to direct bridges if (link[u] != pre[u]) return; if (deg < 0) { // need more coming in from above // pi needs to go from parent->u if (edges[pi].S == u) dir[pi] = 'R'; else dir[pi] = 'L'; } else if (deg > 0) { // there are nodes above me that need me // need to go from u->parent if (edges[pi].F == u) dir[pi] = 'R'; else dir[pi] = 'L'; } } int main() { scanf("%d %d", &N, &M); for (int i = 0; i < M; i++) { int u,v; scanf("%d %d", &u, &v); adj[u].eb(v, i); adj[v].eb(u, i); dir[i] = 'B'; edges.eb(u,v); } scanf("%d", &P); for (int i = 0; i < P; i++) { int u,v; scanf("%d %d", &u, &v); outdeg[u]++; indeg[v]++; } for (int u = 1; u <= N; u++) { if (pre[u] == 0) { dfs(u, -1); } } for (int i = 0; i < M; i++) { printf("%c", dir[i]); } }

컴파일 시 표준 에러 (stderr) 메시지

oneway.cpp: In function 'int main()':
oneway.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   67 |     scanf("%d %d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:70:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   70 |         scanf("%d %d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:77:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   77 |     scanf("%d", &P);
      |     ~~~~~^~~~~~~~~~
oneway.cpp:79:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   79 |         int u,v; scanf("%d %d", &u, &v);
      |                  ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...