이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef int in;
#define int long long
#define s second
#define f first
const long double EPS=1e-9;
const int MOD=1e9+7;
const int N=1e6;
int n,m,k;
vector<int> adj[100005];
map<pair<int,int>,int> ed;
bool b = 0;
int f[100005];
bool vis[100006],tar[100005];
int dfs(int node,int par){
vis[node] = 1;
int ret = 0;
if(tar[node]){
ret = 1;
}
for(int i = 0 ; i < adj[node].size() ; i ++){
int f1 = adj[node][i];
if(f1 == par){
continue;
}
int ans = dfs(f1,node);
f[ed[{node,f1}]] += ans;
ret = max(ret,ans);
}
return ret;
}
in main(){
cin >> n >> m >> k;
for(int i = 0 ; i < n - 1 ; i ++){
int x,y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
ed[{x,y}] = i + 1;
ed[{y,x}] = i + 1;
}
for(int i = 0 ; i < m ; i ++){
int x,y;
cin >> x >> y;
memset(tar,0,sizeof tar);
for(int j = 1 ; j < x ; j ++){
int z;
cin >> z;
tar[z] = 1;
}
dfs(y,-1);
}
vector<int> v;
for(int i = 1 ; i <= n ; i ++){
//cout << f[i] << endl;
if(f[i] >= k){
v.push_back(i);
}
}
cout << v.size() << endl;
for(int i = 0 ; i < v.size() ; i ++){
cout << v[i] << " ";
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
railway.cpp: In function 'long long int dfs(long long int, long long int)':
railway.cpp:29:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i = 0 ; i < adj[node].size() ; i ++){
| ~~^~~~~~~~~~~~~~~~~~
railway.cpp: In function 'in main()':
railway.cpp:70:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int i = 0 ; i < v.size() ; i ++){
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |