이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define F first
#define S second
#define ALL(x) x.begin(),x.end()
#define random(l, r) (l + rand() % (r - l + 1))
#define int long long
#define maxn 500005
#define bit(x, i) ((x >> i) & 1)
#define pii pair<int, int>
#define MOD 1000000007
#define Task "BIKERACE"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int n,m,low[maxn],id[maxn],dem = 0,cnt,num = 0,scc[maxn];
vector<int>adj[maxn],luu[maxn];
ordered_set st[10105];
void Add(int &a,int b)
{
a += b;
if(a >= MOD)a -= MOD;
if(a < 0)a += MOD;
}
stack<int>s;
void DFS(int u)
{
low[u] = id[u] = ++dem;
s.push(u);
++num;
for (int v : adj[u]) {
if (!id[v]) {
DFS(v);
low[u] = min(low[u], low[v]);
if (low[v] == id[u]) {
scc[++cnt] = 0;
while(1){
int x = s.top();
s.pop();
luu[cnt].push_back(x);
luu[x].push_back(cnt);
++scc[cnt];
if(x == v)break;
}
luu[cnt].push_back(u);
luu[u].push_back(cnt);
++scc[cnt];
}
} else low[u] = min(low[u], id[v]);
}
}
int sz[maxn],ans = 0;
void Tinh(int u, int par) {
sz[u] = (u <= n);
for (int v : luu[u]){
if (v == par)continue;
Tinh(v,u);
ans += 2ll * scc[u] * sz[u] * sz[v];
sz[u] += sz[v];
}
ans += 2ll * scc[u] * sz[u] * (num - sz[u]);
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(Task".inp", "r"))
{
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
cin >> n >> m;
for(int i = 1; i <= n; i++) scc[i] = -1;
for(int i = 1; i <= m; i++)
{
int u,v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
cnt = n;
for(int i = 1; i <= n; i++){
if(id[i])continue;
num = 0;
DFS(i);
Tinh(i,0);
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | freopen(Task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
count_triplets.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | freopen(Task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |